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

star_zero

12/10/2021, 1:53 AM
Which is the better own dialog component in Jetpack Compose?
z

Zach Klippenstein (he/him) [MOD]

12/10/2021, 2:18 AM
What do the button functions in the first case do if they're not composable?
s

star_zero

12/10/2021, 2:25 AM
here is first case full code.
second case
Since the dismiss button may not be displayed, null can be passed.
o

Omar Leyva

12/10/2021, 2:53 AM
imo, the 2nd case doesn’t seem to make a big difference from just using an AlertDialog directly. If you want to abstract the composables used internally inside your SimpleAlertDialog, the 1st case looks preferable. I recently created a similar dialog wrapper where callers pass a DialogButton object that contains the text & callback values. Here’s a gist: https://gist.github.com/omar-leyva/72b2d176cfc44cd99694adc8ccac0504
s

star_zero

12/10/2021, 3:01 AM
I’m wondering if I should always use the Slot API Pattern for my components. https://chris.banes.dev/slotting-in-with-compose-ui/
I think the first case is easy to use but, not flexible. As you said, 2nd case is not a big different from just using an AlertDialog.
IMO: Slot API Pattern is better for reusable generic layouts. This is not the right choice for some UI parts. In this case, depending on whether the dialog is a reusable general layout or a UI part. Our team will consider Dialog as a UI part. Therefore, the first case is better.
2 Views