Mikolaj
03/01/2024, 10:33 AM@Composable
, wasn't compiled to native. I discovered that when I added the @Composable
annotation to a top-level function, it wasn't generated in the resulting .h
file. @Dima Avdeev, perhaps it would be beneficial to include this information in the documentation? Thank you!Pavel Shishkin
03/01/2024, 10:51 AM@Composable
functions are slightly modified by compose compiler (additional parameters added), so they are not expected to be called directly from outside world (you have no information about which parameters you need to provide to such function)
therefore, they are not exported in native artifactsMikolaj
03/01/2024, 11:25 AMPavel Shishkin
03/01/2024, 12:28 PMMikolaj
03/01/2024, 12:39 PMOleksandr Karpovich [JB]
03/01/2024, 1:08 PMi could use the method in AndroidCould you please explain or show how you use it? Do i understand correctly that you try to call a Composable function from non-composable code/function/etc?
Ivan Matkov
03/01/2024, 1:08 PMIt was also misleading because i could use the method in AndroidCould you clarify this? Because it sounds as incorrect approach in general. You cannot just call composable functions outside of composable context. It sounds similar to question like "why I cannot call composable functions from onClick callback"
Mikolaj
03/01/2024, 1:14 PMandroidApp
(i.e the MainView()
method in todoapp example from CMP repo - https://github.com/JetBrains/compose-multiplatform/blob/master/examples/todoapp-li[…]App/src/androidMain/kotlin/example/todoapp/lite/MainActivity.kt) But if you try to call MainView from ios it is just not there.
Now I understand why but imo it could not be clear at first glanceMikolaj
03/01/2024, 1:15 PMOleksandr Karpovich [JB]
03/01/2024, 1:15 PMMainView()
in the example above is called from another Composable.
So if you want to call a Composable on ios from kotlin code (same as an example above - it's called in kotlin code), it's possible.Mikolaj
03/01/2024, 1:20 PMOleksandr Karpovich [JB]
03/01/2024, 1:26 PMI can call those methods when I import the library on Androidonly when using kotlin, not java 🙂
but those methods do not exist on native (Swift/ObjC) iOSthat's true, they're not exposed to ObjC. but can be called in kotlin code. Kotlin is required because Composable calls are expected to be transformed by the Compose compiler plugin for Kotlin. Even if they were exposed to ObjC, it would be quite difficult to properly build a correct composition manually. _ I think, the takeaway from this thread is to explicitly note this behaviour in the documentation.
Mikolaj
03/01/2024, 1:28 PMPavel Shishkin
03/01/2024, 1:29 PM