I know I can try this myself, but does anyone have...
# compose-desktop
c
I know I can try this myself, but does anyone have any thoughts with rememberSaveable() on desktop? Or is it generally safe to use there as well?
👀 1
a
Yes. On desktop
remeberSaveable
is just the same as
remember
.
t
This is because there is no scope to save to You could theoretically create your own but it has its own querks and bugs. So i wouldn't recommend it https://kotlinlang.slack.com/archives/C01D6HTPATV/p1616452277151800?thread_ts=1616452277.151800&cid=C01D6HTPATV
t
In my tests it works the same like in Android. Currently you have to implement navigation yourself like this:
Copy code
@Composable
fun <T> SaveableCrossfade(
    targetState: T,
    modifier: Modifier = Modifier,
    animationSpec: FiniteAnimationSpec<Float> = tween(),
    content: @Composable (T) -> Unit
) {
    val saveableStateHolder = rememberSaveableStateHolder()
    Crossfade(
        targetState = targetState,
        modifier = modifier,
        animationSpec = animationSpec
    ) {
        saveableStateHolder.SaveableStateProvider(it.hashCode()) {
            content(it)
        }
    }
}
c
@Mark Murphy ^
👍🏻 1
a
yes, android’s savedinstancestate is just one of the use cases for rememberSaveable() so it is still useful on desktop for navigation like usecase as shared above. other difference is that on Android you can only put there types which are supported by Bundle, on Desktop you can put there any type. which means in the common code you should use it with types which are supported on all the target platforms