Mikołaj Kąkol
02/23/2021, 7:25 PMrememberSaveableStateHolder
is broken in somehow in alpha12. Consider example from here: https://github.com/androidx/androidx/blob/androidx-main/compose/runtime/runtime-sa[…]/compose/runtime/saveable/samples/SaveableStateHolderSamples.kt
and change
Box(modifier) {
restorableStateHolder.SaveableStateProvider(currentScreen) {
content(currentScreen)
}
}
to
Box(modifier) {
restorableStateHolder.SaveableStateProvider(currentScreen) {
Crossfade(targetState = currentScreen) {
content(it)
}
}
}
you will notice that animation doesn’t work.
If you will remove that state holder:
Box(modifier) {
Crossfade(targetState = currentScreen) {
content(it)
}
}
crossfade works.
So either stateholder
is broken or crossfade
. From what I unsderstand problem is that Crossfade implementation uses remember
to store items to render during transition.
What I wanted to achieve is some nice animation between screens. What to do? 🤔 🙀Crossfade(targetState = currentScreen) {
Box(modifier) {
restorableStateHolder.SaveableStateProvider(currentScreen) {
content(it)
}
}
}
crashes after screen change with
java.lang.IllegalArgumentException: Key screen2 was used multiple times
at androidx.compose.runtime.saveable.SaveableStateHolderImpl$SaveableStateProvider$1.invoke(SaveableStateHolder.kt:91)
Andrey Kulikov
02/23/2021, 11:28 PMAlbert Chang
02/24/2021, 12:21 AMcurrentScreen
changes, instead of recomposing the composable passed to SaveableStateProvider
, a new composition is created, which means that the Crossfade
is not the same to the old Crossfade
thus not working.Mikołaj Kąkol
02/24/2021, 6:14 AMCrossfade(targetState = currentScreen) {
Box(modifier) {
restorableStateHolder.SaveableStateProvider(it) {
content(it)
}
}
}
amazing :)