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

Kazemihabib1996

04/06/2020, 3:17 PM
At the moment state (Model) is not retains on orientation change. Is this supposed to change in future or we are supposed to use ViewModel with jetpack compose?
z

Zach Klippenstein (he/him) [MOD]

04/06/2020, 3:21 PM
Since layouts in Compose are kotlin and not XML resources, you can probably handle rotation config changes yourself instead of letting the system restart your activity. You could also use
rememberSavedInstanceState
.
👍 1
l

Leland Richardson [G]

04/06/2020, 3:23 PM
savedInstanceState
is the persisted version of
state
(equivalent to
rememberSavedInstanceState { mutableStateof(…) }
👍 1
k

Kazemihabib1996

04/06/2020, 3:28 PM
@Leland Richardson [G] why it's not the default behavior of remeber?
l

Leland Richardson [G]

04/06/2020, 3:30 PM
because there is a maximum transaction size and it would be easy to surpass it if we dumped everything into it. also, not all types are serializable
👍 1
also, slightly related, if you are running a pure compose app, you should probably turn off restarts on configuration changes
but savedInstanceState is still needed for process death in any event
k

Kazemihabib1996

04/06/2020, 3:32 PM
Yeah, turning it off is a good idea
thank you.
s

Sinan Kozak

04/06/2020, 5:23 PM
About turning off configuration changes, will compose handle view/UI rotation depending on the device rotation? I can only imagine a nice continues animation from portrait to landscape. Will it be possible?
l

Leland Richardson [G]

04/06/2020, 5:25 PM
that’s the goal. i think it would require some platform APIs to handle properly and don’t remember if they were available or not
my desire was to have all of the configuration (orientation, screen size, etc.) all as just part of some model object that you could use in your composable if you wanted, and it would automatically adjust (recompose) whenever the configuration changed at all
👍 7
🔥 1
4 Views