HomeiOS Developmentandroid - Decomposable hundreds view a number of instances

android – Decomposable hundreds view a number of instances


I’m new to Kotlin multiplatform initiatives and am at the moment engaged on implementing a navigation controller utilizing Decomposable structure (android & iOS). The next course of I’ve structured relies on the documentation, however sadly discovered a key limitation. That’s, when a brand new part is pushed/bringToFont in navigation stack, it calls all earlier parts of kid stack a number of instances, and after which navigates the specified part finally. This inefficiency considerably impacts UI navigation pace. I’m searching for an answer to correctly construction navigation in multiplatform mission.

class Screen_1_Component(
    componentContext: ComponentContext,
    val onClickGo: ()->Unit,
) {}
class Screen1View(val part: Screen_1_Component) {
    @Composable enjoyable loadView(){
        Button(content material = { Textual content("Go To Display screen 2") }, onClick = { part.onClickGo() })
    }
}

class Screen_2_Component(
    componentContext: ComponentContext,
    val onClickBack: ()->Unit,
) {}

class Screen2View(val part: Screen_2_Component) {
    @Composable enjoyable loadView(){
        Button(content material = { Textual content("Again To Display screen 1") }, onClick = { part.onClickBack() })
    }
}

class Root_Component(componentContext: ComponentContext): ComponentContext by componentContext {
    non-public val navigation = StackNavigation<_Configuration>()
    val childStack = childStack(
        supply = navigation,
        serializer = _Configuration.serializer(),
        initialConfiguration = _Configuration.Screen1,
        handleBackButton = true,
        childFactory = ::createChild
    )
    @OptIn(ExperimentalDecomposeApi::class)
    non-public enjoyable createChild(config: _Configuration, context: ComponentContext): _Child {
        return when(config) {
            is _Configuration.Screen1 -> _Child.Screen1(
                Screen_1_Component(context, onClickGo = {
                    navigation.bringToFront(_Configuration.Screen2)
                })
            )
            is _Configuration.Screen2 -> _Child.Screen2(
                Screen_2_Component(context, onClickBack = {
                    navigation.pop()
                })
            )
        }
    }

    sealed class _Child {
        information class Screen1(val part: Screen_1_Component): _Child()
        information class Screen2(val part: Screen_2_Component): _Child()
    }

    @Serializable sealed class _Configuration {
        @Serializable information object Screen1: _Configuration()
        @Serializable information object Screen2: _Configuration()
    }

    @Composable enjoyable showView() {
        val childStack by childStack.subscribeAsState()
        Kids(
            stack = childStack,
            animation = stackAnimation(slide())
        ) { baby ->
            when(val occasion = baby.occasion) {
                is Root_Component._Child.Screen1 -> {
                    Screen1View(occasion.part).loadView()
                }
                is Root_Component._Child.Screen2 -> {
                    Screen2View(occasion.part).loadView()
                }
            }
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments