https://kotlinlang.org logo
Title
c

Colton Idle

04/29/2021, 11:50 PM
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

Albert Chang

04/30/2021, 5:33 AM
Yes. On desktop
remeberSaveable
is just the same as
remember
.
t

TheMrCodes

04/30/2021, 7:42 AM
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

Timo Drick

04/30/2021, 11:17 AM
In my tests it works the same like in Android. Currently you have to implement navigation yourself like this:
@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

Colton Idle

04/30/2021, 12:44 PM
@Mark Murphy ^
👍🏻 1
a

Andrey Kulikov

04/30/2021, 12:47 PM
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