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

ste

01/15/2022, 10:03 AM
Hi! I'd like to know if I'm incurring an anti-pattern. Let's say I need to display the same composable (a
TextSnackBar
which shows a pop-up message over the screen and then disappears) over different screens. There's a
TextSnackBarState
that exports the method
display(message: String)
. I don't know which approach I should embrace: (see thread)
1. Declare a "global"
TextSnackBar
and expose its state via `CompositionLocalProvider`: I can show any message anytime I want to with ease, but achieving custom style/behavior is hard. 2. Declare a "local" `TextSnackBar`: each screen has its own
TextSnackbarState
that can be used to display different messages: more code, more nesting, avoids global state but achieving custom style/behavior is hard too. 3. Declare as many
TextSnackBar
I need in each screen: if I have two different messages, I need two
TextSnackBar
with their own
TextSnackBarState
. More code, same nesting as 2), custom style/behavior is easy to do.
Well, at the moment I don't need custom behaviors nor styles, so I opted for 1). However I don't know if it's a bad idea