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

K Merle

02/14/2023, 11:34 AM
I am trying to save state of a dialog on configuration change, but lambdas are giving me an issue during serialization. How do you guys handle custom dialog states during configuration change?
z

Zun

02/14/2023, 1:17 PM
Is this a Jetpack compose question? You can simply remember the state
t

Thomas Kranzer

02/14/2023, 1:22 PM
i assume you want to save and restore your dialog model within your ViewModel, right? you should only save the UI State (the information that is necessary to restore the UI) and not the action that correspond to certain UI Elements. So instead of having a lambda within your dialog model, consider using some declarative abstraction of that action, this can be a enum or a sealed class. your dialog model could look like this:
Copy code
DialogModel(
    title = "Confirm", 
    action = DialogAction.Confirm
)
k

K Merle

02/16/2023, 4:12 PM
Thank you!
4 Views