<@UHAJKUSTU> iOS App's nav backstack is getting cl...
# decompose
v
@Arkadii Ivanov iOS App's nav backstack is getting cleared when device theme is changed I remember this was fixed on Android with the
discardSavedState
param Code in Thread
Copy code
object MedialApp {

    private val deeplink = MutableStateFlow<String?>(null)

    /**
     * Call from iOS
     */
    fun setUpDeeplink(deeplink: String?) {
        this.deeplink.update { deeplink }
    }

    @OptIn(ExperimentalDecomposeApi::class, ExperimentalComposeApi::class)
    fun viewController(): UIViewController {

        return ComposeUIViewController(
            configure = {
                onFocusBehavior = OnFocusBehavior.DoNothing
                opaque = false
            },
        ) {
            val permissionController = remember { PermissionsController() }
            val deeplink by this.deeplink.collectAsState()
            val backDispatcher = BackDispatcher()
            val rootComponent = RootComponentImpl(
                componentContext = DefaultComponentContext(
                    lifecycle = ApplicationLifecycle(),
                    backHandler = backDispatcher
                ),
                deeplink = deeplink,
                permissionController = permissionController
            )
            PredictiveBackGestureOverlay(
                backDispatcher = backDispatcher, // Use the same BackDispatcher as above
                backIcon = { progress, _ ->
                    PredictiveBackGestureIcon(
                        imageVector = Icons.Default.ArrowBack,
                        progress = progress,
                    )
                },
                modifier = Modifier.fillMaxSize(),
            ) {
                MedialApp(
                    component = rootComponent,
                    modifier = Modifier.fillMaxSize()
                )
            }
        }
    }

}
a
Could you please elaborate, what's the actual issue?
v
If I change the device theme from light -> dark and vice versa The app seems to start again from the 1st screen
a
Got it, and you want to prevent it, right?
v
yes
a
Ok. I'm not a pro iOS dev, so I might be wrong. I think this happens because the app is restarted and the state is not saved. I would first check if there is any way of preventing the app from being restarted. But if there is not, as a last resort you can save and restore the state manually. See here: https://github.com/arkivanov/Decompose/blob/0708bbda5bca9df0669944d8893736353e418c43/sample/app-ios/app-ios/app_iosApp.swift#L39
v
Thanks, how can i do this in the Kotlin side?
a
There are two parts, Swift-side and Kotlin-side. You can check the sample. Also, I would try looking for another solution first. Maybe there is a configuration flag to prevent the restart, or something similar.
v
I'll take a look, thanks
👍 1
@Arkadii Ivanov for this solution, in the sample the rootComponent creation is on the Swift Side, how to do this when everything is in shared Compose side? I'm not able to find anything on stopping ios app from restarting
a
I don't think it's possible to implement everything in Kotlin. I suggest to at least create
DefaultComponentContext
on the Swift side. I would also create the
RootComponent
on the Swift side, as there might be iOS specific dependencies.