Fudge
07/20/2020, 7:47 PMColumn {
var on by state { true }
Button(onClick = { on = !on }) {
Text(text = "Toggle", style = textStyle.h1)
}
val list = @Composable {
LazyColumnItems(items = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) {
Text(text = it.toString(), style = textStyle.h1)
}
}
if (on) {
list()
} else {
list()
}
}
Here we have a scrolling list, with a button above it, that seemingly, does nothing. However, it doesn't - it resets the current scroll progress in the scrolling list. I have a feeling this is the intended behavior (unfortunately).
I have a less trivial case where the same list is being used at multiple places, but it loses its scroll progress when it gets invoked through a different branch of code. It might be possible to somehow structure the code such that only one invocation occurs, but I find that difficult. Is there some way to make compose understand this is the same list?romainguy
07/20/2020, 7:55 PMkey()
or am I incredibly mistaken here?Fudge
07/20/2020, 8:05 PMjim
07/20/2020, 8:08 PMval myValue = if(on) ... else ...
list(myValue)
val myState = remember { SomeState() }
if(on) list(myState)
else list(myState)
Then you store things like the scroll position into myState, and then it doesn't matter if you are in a different branch because the list function is a pure function of its inputs and thus isn't stateful so no state is lost.Fudge
07/20/2020, 8:17 PMThen you store things like the scroll position into myStatehow can I store this if LazyColumnItems does not provide it?
jim
07/20/2020, 8:25 PMLazyColumnItems
should expose scroll position, probably as a hoisted state object; please feel free to file a bug on LazyColumnItems
(please be gentle on us though, keep in mind that this widget is still under active development/iteration and this API is not yet done)Fudge
07/20/2020, 8:30 PMLazyColumnItems
's state? Imagine if the component had 20 different fields (or state variables, rather) that it uses to manage its state, do I then need to pull them up into my component and store them so the component I am using doesn't forget everything?LazyColumnItems
need to provide api to expose its state to me, it also needs parameters for me to feed my state into it (that I got from said component).jim
07/20/2020, 8:34 PMLeland Richardson [G]
07/20/2020, 8:35 PMAndrey Kulikov
07/20/2020, 8:45 PMLazyColumnItems
is one of my next plans, so should be available at some pointFudge
07/20/2020, 8:46 PMSplitView
, it shows 2 components side by side, left
, and right
.
When swiping from left to right, the left
component is the previous component, and the right
component is the current component.
When swiping from right to left*,* the left
component is the current component, and the right
component is the next component.
In this case, the same component is represented as different arguments to the same method, so in the case of a scrolling list it would lose its scroll position when swiping.