Thread
#compose
    Archie

    Archie

    2 years ago
    How to you keep the value of
    state { ... }
    across configuration changes?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    I think using the saved state registry should help, i.e. use
    savedInstanceState {}
    instead of
    state {}
    matvei

    matvei

    2 years ago
    Substitute
    state {}
    for
    savedInstanceState {}
    Oh Zach is so fast 😅
    Archie

    Archie

    2 years ago
    ohh i see thank you 😄
    Sinan Kozak

    Sinan Kozak

    2 years ago
    why are those two different thing? Is there a benefit choosing
    state
    over
    savedInstanceState
    ?
    Ricardo C.

    Ricardo C.

    2 years ago
    savedInstanceState
    has the usual restrictions. You can’t put big objects there and you’ll have to parcel/serialize them
    Adam Powell

    Adam Powell

    2 years ago
    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.
    So yes, parts of this are WIP 🙂
    Sinan Kozak

    Sinan Kozak

    2 years ago
    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?
    Adam Powell

    Adam Powell

    2 years ago
    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.
    (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
    Sinan Kozak

    Sinan Kozak

    2 years ago
    I will definitely experiment with transition for this, Just to check if having smooth rotation is possible 😄
    Adam Powell

    Adam Powell

    2 years ago