ursus
07/24/2024, 3:39 PMBadge component like this
Should I model the variants as NoteBadge, AttentionBadge etc i.e. a dedicated composable
or
a Badge(variant = Note/Attention/etc) ?
I did the first, but badge often represents a status of something -> i.e. it transitions between different variants of the badge
if I have a
when (status) {
is Foo -> SuccessBadge()
is Bar -> ErrorBadge()
}
that "breaks" structured identity right?Arsildo Murati
07/24/2024, 3:49 PMArsildo Murati
07/24/2024, 3:50 PMursus
07/24/2024, 3:50 PMursus
07/24/2024, 3:50 PMArsildo Murati
07/24/2024, 3:51 PMArsildo Murati
07/24/2024, 3:51 PMursus
07/24/2024, 3:51 PMursus
07/24/2024, 3:52 PMArsildo Murati
07/24/2024, 3:53 PMursus
07/24/2024, 3:53 PMinterface?Arsildo Murati
07/24/2024, 3:53 PMursus
07/24/2024, 3:53 PMursus
07/24/2024, 3:56 PMinterfaceursus
07/24/2024, 3:56 PMclass ButtonColors(
backgroundColor: Color,
disabledBackgroundColor: Color,
contentColor: Color,
disabledContentColor: Color
) {
fun backgroundColor(enabled: Boolean): Color { ... }
fun contentColor(enabled: Boolean): Color { ... }
}
object ButtonDefaults {
// default factory for the class
// can be @Composable to access the theme composition locals
fun colors(
backgroundColor: Color = ...,
disabledBackgroundColor: Color = ...,
contentColor: Color = ...,
disabledContentColor: Color = ...
): ButtonColors { ... }
}
?Arsildo Murati
07/24/2024, 3:57 PMursus
07/24/2024, 3:57 PMArsildo Murati
07/24/2024, 3:57 PMArsildo Murati
07/24/2024, 3:57 PMursus
07/24/2024, 3:58 PMcolors: ButtonColors
which then can be anything (Pink, Yellow, .. )ursus
07/24/2024, 3:59 PMArsildo Murati
07/24/2024, 3:59 PMArsildo Murati
07/24/2024, 3:59 PMArsildo Murati
07/24/2024, 4:00 PMursus
07/24/2024, 4:00 PMFilledButton OutlinedButtonArsildo Murati
07/24/2024, 4:00 PMursus
07/24/2024, 4:00 PMPrimaryButton() SecondaryButton()ursus
07/24/2024, 4:01 PMMyButton(variant = Primary/Secondary)Arsildo Murati
07/24/2024, 4:01 PMArsildo Murati
07/24/2024, 4:02 PMursus
07/24/2024, 4:02 PMursus
07/24/2024, 4:02 PMArsildo Murati
07/24/2024, 4:03 PMComponentColors or ComponentElevation classes allow for more granular control, where the user can specify the enabled and disabled colors/elevation separately.ursus
07/24/2024, 4:04 PMursus
07/24/2024, 4:05 PMTypographyAlbert Chang
07/24/2024, 4:18 PMursus
07/24/2024, 4:19 PMSkaldebane
07/24/2024, 5:20 PMSkaldebane
07/24/2024, 5:23 PMAnimatedContent or something like that, but it may not look super smooth.
2. animate from the inside, e.g. by adding a Modifier.animateSizeChanges to the inner text, or making the color an animated state derived from the badge status, but i'm not sure if that's very idiomaticSkaldebane
07/24/2024, 5:26 PMursus
07/24/2024, 5:39 PMursus
07/24/2024, 5:40 PMAlex
07/24/2024, 8:21 PMif/else or large when statements, then from a clean code perspective different, smaller, more focused composables (i.e. one for each badge) make more sense too.ursus
07/24/2024, 8:22 PMSkaldebane
07/24/2024, 8:22 PMBadgeImpl composable, and reuse it in every variantSkaldebane
07/24/2024, 8:23 PMursus
07/24/2024, 8:23 PMNoteBadge(text) etc