Reputation: 1765
I have a generic rememberMutableStateListOf used across my app that keeps lists if screen configuration changes, like rotation.
@Composable
fun <T> rememberMutableStateListOf(vararg elements: T): SnapshotStateList<T> {
return rememberSaveable(
saver = listSaver(
save = { stateList -> stateList.toList() },
restore = { list -> list.toMutableStateList() }
)
) {
elements.toList().toMutableStateList()
}
}
The problem is, it works with all devices, but not with tablet. Once the screen is rotated, it shows no elements in, e.g. from portrait to landscape. But when rotating back from landscape to portrait the list contains elements like before.
I do not have a physical device and use the Android emulator (resizable).
What might be the problem?
EDIT:
That's not only for rememberMutableStateListOf
, but also other saveable variables like
var done by rememberSaveable { mutableStateOf(false) }
No saveable variable survives screen rotation, only ViewModel
.
Upvotes: 0
Views: 26