dimsuz
04/06/2022, 4:44 PMimmutableStateOf(value)
?
Usecase:
val state = when (orientation) {
Orientation.Landscape -> animateDpAsState(32.dp)
Orientation.Portrait -> immutableStateOf(16.dp)
}
I could use mutableStateOf(16.dp)
of course, just thought maybe something more lightweight exists.Adam Powell
04/06/2022, 5:27 PManimateDpAsState
? 🤔dimsuz
04/06/2022, 5:38 PMstate
value itself?
I want to animate only in landscape, othewise component is the same:
MyComponent(offset = state.value) // animates offset only in landscape, otherwise it's always 16.dp
dimsuz
04/06/2022, 5:56 PMif
there, sorry: animateDpAsState(if (someFlag) 0.dp else 32.dp)
. otherwise the question is still valid.Adam Powell
04/06/2022, 7:41 PMwhen
with something like
animateDpAsState(
when (orientation) {
Landscape -> if (someFlag) 0.dp else 32.dp
Portrait -> 16.dp
}
)
and as a bonus you can get animation between those two for things like window resizing changing the orientationAdam Powell
04/06/2022, 7:42 PMimmutableStateOf
and you should never need one. Either use the constant directly, or if you're making a late-binding decision and you want a snapshot read to occur more deeply in your UI somewhere, use a () -> T
lambda instead of trying to construct a State<T>
around somethingdimsuz
04/07/2022, 1:14 PM