Mikołaj Kąkol
01/15/2021, 7:49 PMtabA
is visible tabB
is not in composition tree.
My problem is that when I switch between them state is not remembered, for example scroll state. How can I tell to compose to remember this discarded tab, that it can be needed soon?
(sample code in thread)@Composable
fun Testing() = Column {
val tabIndex = remember { mutableStateOf(0) }
Row {
Button(onClick = {
tabIndex.value = tabIndex.value - 1
}) { Text("Previous tab") }
Button(onClick = {
tabIndex.value = tabIndex.value + 1
}) { Text("Next tab") }
}
if (tabIndex.value % 2 == 0) {
ContentForTab1(1)
} else {
ContentForTab2(2)
}
}
@Composable
fun ContentForTab1(tabIndex: Int) {
ScrollableColumn {
(0..100).map { Text("Item in tab: $tabIndex number $it") }
}
}
@Composable
fun ContentForTab2(tabIndex: Int) {
ScrollableColumn {
(0..100).map { Text("Item in tab: $tabIndex number $it") }
}
}
Alex Petitjean
01/15/2021, 7:53 PMLazyColumn
, I think you could lift the LazyListState
out of the tabs and pass it into them (idk if there's a state object for ScrollableColumn
, but that method is deprecated anyway, so you might want to just switch)Mikołaj Kąkol
01/15/2021, 7:55 PMTash
01/15/2021, 9:28 PMMikołaj Kąkol
01/30/2021, 8:27 PM