Hi <@UHAJKUSTU> is there a way to preserve a dialo...
# decompose
j
Hi @Arkadii Ivanov is there a way to preserve a dialog during orientation change and execute the correct lambda?
I have a component with a slot-navigation
I have set persistent to true
My Dialog-Config looks like this:
Copy code
@Parcelize
    data class DialogConfig(
        val title: StringResource,
        val message: StringResource,
        val onConfirm: () -> Unit = {},
    ) : Parcelable
a
You should never have lambdas in your persistent configurations. Configurations are serialized, and you are basically leaking everything that is captured by the lambda.
j
yes
a
Just supply the callback when you instantiate the dialog component
j
so If I have two different dialogs for different usecase then I have to supply to different callbacks right?
a
Yep
j
thats the only way ... only simple callbacks are working otherwise its leaking due to the lambda bound to a component
a
I don't get it. If you pass callbacks via constructor and don't put callbacks in configurations, there should be no leaks.
j
hard to explain. I thought I could pass different actions via config to my dialog component, but that is obviously not working because If I do so my components are not cleaned up correctly. Aftern rotation I do have 2 components of the same type. Thats because I added an onConfirm lambda via config and the old component is not cleaned up
a
You can distinguish your cases when creating the dialog component, based on the configuration
You can have separate configuration classes for different cases
j
yes, maybe thats the problem. I thought I could just have one global config and pass lambda-callbacks to it
a
Yeah. That's an incorrect approach 🙂
j
ok, I will try with several configs. In my specific case a dialog config If I really want to delete something and a dialog config If I really want to cancel the current changes
a
You can also add an enum to the configuration, and use that for distinguishing. That would be another way.
j
yep
thanks for help
👍 1