What would be the idiomatic way to have a reusable...
# compose
t
What would be the idiomatic way to have a reusable dialog in compose that accept some input and trigger a callback?
z
You would have some higher-level app state that would indicate that the dialog needs to be visible, and a callback into that layer that would cause the layer to change the state to indicate the dialog doesn’t need to be shown anymore. Then in your composable you consume that state to determine whether to call the Dialog composable, and inside the dialog content call the appropriate method to bubble the event up to the right layer that changes the show dialog flag.
t
Thanks but how to bubble the callback or the event down for action after the dialog choice is made? Like a dialog in a music player with tons of screen that display playable content and when you click an item an something is playing a dialog ask if content should be played or queued. Content being a suspend lambda that will generate it in demand.
z
If you’re asking how to send state and events between architectural layers, there is a wealth of blogs and talks about all kinds of different architectures and approaches. It’s a lot to try to answer in a slack thread.
t
Well not really the issue is purely about dialogs in the compose realm with data that can't be serialized. So not as simple as navigation destination for example.
z
There’s nothing special about dialogs in compose. They’re just other composables - all the usual practices for passing state and events apply.
t
That's the point leading to linking everything tight to pass the suspend callback up to something and the state and the dismiss. At this point it's better to use compositionlocal.