Hey guys. In KMP code where ui is also being shared in one of the module. Can we expect platform to ...
k
Hey guys. In KMP code where ui is also being shared in one of the module. Can we expect platform to render on behalf. e.g @Composable actual fun RenderSomeUi() { // IOS render its ui here from native side not kotlin wrappers of obj C }
Hey @Abdullah @Andrei Salavei Can you Help me.
k
No To be specific My code is something expect GifRenderer(url:String) For ios actual GifRenderer(url:String) { // here I want something so that ios will render its own ui here // i knw the way we can code here for uiKit but I want swit ui view here which ios will inject here }
m
since composables can be arguments, you could create a UIKitView in the iOs sourceset and pass it to composable from the common source set, either by using expected/actual (a composable function can be part of a class, therefore it can be part of an expected class), or by reversing the relationship and calling the common composable from the iOs sourceSet and passing the UiKitView based composable as an argument there
As a general advice, consider Kotlin multiplatform as dependency injection on crack, like, if you have this problem within a single platform and all you want to do is to have several implementation, how do you do it? Then, take advantage of mechanisms like expected/actual, or just go with regular DI.
m
is there any performance impact using expect/actual which I suppose would be using interpolation vs dependency injection?