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

Archie

07/24/2020, 12:58 PM
How to you keep the value of
state { ... }
across configuration changes?
z

Zach Klippenstein (he/him) [MOD]

07/24/2020, 1:00 PM
I think using the saved state registry should help, i.e. use
savedInstanceState {}
instead of
state {}
☝️ 3
❤️ 1
m

matvei

07/24/2020, 1:00 PM
Substitute
state {}
for
savedInstanceState {}
😂 1
❤️ 1
Oh Zach is so fast 😅
a

Archie

07/24/2020, 1:03 PM
ohh i see thank you :D
s

Sinan Kozak

07/24/2020, 1:15 PM
why are those two different thing? Is there a benefit choosing
state
over
savedInstanceState
?
🤔 1
r

Ricardo C.

07/24/2020, 1:16 PM
savedInstanceState
has the usual restrictions. You can’t put big objects there and you’ll have to parcel/serialize them
☝️ 2
a

Adam Powell

07/24/2020, 1:20 PM
Once you get into the discussion of, "yes but what about ViewModels? Those don't need to parcel!" you also get into the property of config changes where you commonly rearrange the UI shape in those different configurations and the API has to again account for different things. Compose doesn't know which parts of a very different composition shape are semantically equivalent and how to key them without your help.
👍 2
So yes, parts of this are WIP 🙂
👍 1
s

Sinan Kozak

07/24/2020, 1:27 PM
A different question, could compose has its own rotation state independent from activity? Is this possible, having portrait locked activity and letting compose to handle rotation?
a

Adam Powell

07/24/2020, 1:33 PM
Camera apps more or less do that but it would have a lot of side effects affecting a lot of view interop. There's nothing stopping one from trying it, really. If you're looking primarily to preserve state, marking the host activity as handling its own configuration changes is probably a less disruptive path.
👍 1
(and it's also worth noting that the activity configuration signals to do the camera-style thing are quite new in terms of which API level they were introduced in, if I recall)
It would, however, open the door to doing some neat things with transition animations
👌🏻 1
s

Sinan Kozak

07/24/2020, 1:36 PM
I will definitely experiment with transition for this, Just to check if having smooth rotation is possible 😄
a

Adam Powell

07/24/2020, 4:12 PM