Hey folks. New to compose. I have a very weird dou...
# compose
f
Hey folks. New to compose. I have a very weird doubt, and it might just be because of my lack of being able to completely “Think in Compose”. I have a scenario where I would need to delay the data received by a LazyList so that I can show the list first (AnimatedVisibility) and then let the
Modifier.animateItemPlacement()
animations run. I dont want to keep copies of my data, how can I delay this ?
1
e
You have to keep that state. That is the “thinking in compose” way
f
First of all, thank you for responding @efemoney. But I am sorry I didnt get it.
s
The UI is the state, so if you want the UI to show something, and then show something else later, you have to make the state be that something first, and later make it be that new state, just as Efeturi said. So you’d need to somehow keep that “new” state somewhere else, and after that delay change the state that is reflected in the UI with that new state.
e
See this “search logic” example
queryState
is for all intents and purposes, the “input” state. This is what you want to delay. Just like in the screenshot, you keep a copy of the state in another variable
query
then use a launched effect or some other coroutine machinery to run you delay logic In my case (ie this example) I wanted to add debounce logic to the incoming search query. Its implemented in a LaunchedEffect that monitors the input
queryState
, debounces it and then updates the
query
, which the rest of the logic then depends on.
f
Thats really helpful. Thanks folks.