https://kotlinlang.org logo
#compose
Title
# compose
f

Fudge

07/28/2020, 10:48 AM
What should I do if displaying a few items in a
LazyColumnItems
lags the screen for like 0.5 seconds when displayed? Is this perhaps because this is a preview, or do I have some way of profiling where the device spends its time?
t

Timo Drick

07/28/2020, 12:42 PM
It should not lag in any way. Maybe you are displaying very big images?
f

Fudge

07/28/2020, 12:45 PM
not images, just some text with some draggable modifiers
t

Timo Drick

07/28/2020, 12:46 PM
I think we need more information to help you. Can you provide some code?
f

Fudge

07/28/2020, 12:53 PM
there is quite a bit of stuff
I'll try to solve a problem I have now where
remember{}
doesn't remember at all and then try to simplify it
This is a very frustrating thing i've found about compose, because it doesn't use normal OOP semantics but instead hidden magics it's unclear when how or why something is saved in
remember{}
and the likes
t

Timo Drick

07/28/2020, 1:29 PM
for me val variable by state { } works most of the time better
And it will be deleted wenn the Composable is removed from the view
f

Fudge

07/28/2020, 1:35 PM
Is there a way to keep the state even when the composable is removed from the view? so that the state remains when you navigate back and forth
t

Timo Drick

07/28/2020, 1:40 PM
Yes just define the variable not inside of the view.
Copy code
var state by mutableStateOf(initialState)
f

Fudge

07/28/2020, 1:41 PM
I guess that's one way
Isn't
savedInstanceState
supposed to work too? If it survives process death it should survive switching views too
t

Timo Drick

07/28/2020, 1:42 PM
yes you are right. I did not used it yet because in the past it had many problems.
But now it should work as expceted
f

Fudge

07/28/2020, 1:43 PM
I tried
savedInstanceState
, seems like it doesn't work at all
Doesn't survive process death or switching views
h

Halil Ozercan

07/28/2020, 1:45 PM
remember
is confusing because it feels like it's supposed to remember a
variable
but it actually remembers the result of a calculation. So if your composable gets recomposed because of a dependency change,
remember
will trigger again but won't invoke the callback function. So if you've made changes to the local variable that was initialized by
remember
, it will get re-set by initially remembered value