Andrii Yanechko
12/10/2023, 6:49 PMAndrii Yanechko
12/10/2023, 6:50 PMUIImagePickerController
and I see that callback of the delegate got invoked, but when the camera UI dismisses, the application just resets its state (or reloads)Andrii Yanechko
12/10/2023, 6:51 PMsourceType
which is weird)Dennis
12/11/2023, 11:47 AMAndrii Yanechko
12/11/2023, 2:42 PMMutableStateFlow
and the other one, which is more UI related, it observes the StateFlow
and executes transition to a new destination by using the AnimatedContent
Compose function.
The thing that even I have my "logical" part of the navigation under the remember
I see in the logs that it got reinstantiated.
Here how the instantiation of the navigation "router" looks like:
@Composable
fun <D> rememberNavigationState(
mapper: ((D) -> KClass<out ViewModel>?)? = null,
initialConfiguration: TransitionScope.(NavigationState<D>) -> Unit = {},
initialDestination: D,
flowFinalizer: FlowFinalizer,
): NavigationState<D> {
val manager = LocalViewModelManager.current
return remember {
NavigationState(
initialDestination = initialDestination,
initialConfiguration = initialConfiguration,
viewModelExtension = mapper?.let { ViewModelExtension(manager = manager, mapping = it) },
flowFinalizer = flowFinalizer
)
}
}
Dennis
12/11/2023, 2:49 PMģģ
12/15/2023, 4:07 PMThomas
01/08/2024, 7:17 PMThomas
01/08/2024, 7:18 PMrememberSaveable
working on iOS so all state can be kept or so.Andrii Yanechko
01/08/2024, 7:19 PMThomas
01/08/2024, 7:19 PMThomas
01/08/2024, 7:20 PMThomas
01/08/2024, 8:06 PMclass IosSaveableStateFix {
private var registry = SaveableStateRegistry(restoredValues = null) { true }
@Composable
fun Provider(
block: @Composable () -> Unit
) {
CompositionLocalProvider(LocalSaveableStateRegistry provides registry) {
block()
}
DisposableEffect(Unit) {
onDispose {
val savedData = registry.performSave()
registry = SaveableStateRegistry(restoredValues = savedData) { true }
}
}
}
}
usage:
val saveableStateFix = IosSaveableStateFix()
return ComposeUIViewController {
saveableStateFix.Provider {
// your app
}
}
This should fix most state issues because on Android you should already be using rememberSaveable for saving important state like navigation state. Compose itself already uses this a lot for all the views. If you also want to keep viewmodels you still need to save them outside ComposeUIViewController like I showed. (or maybe using rememberSaveable if only targeting iOS?)
Keep in mind I have not really tested this code that well, but it seems to work fine for me.Thomas
01/08/2024, 8:35 PM