Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Jetpack Compose provide separate button types like OutlinedButton, TextButton and Button?

Why does Jetpack Compose provide separate button types like OutlinedButton and TextButton, instead of passing the button style as a parameter to a single Button type?

I understand that this will help us in better code organization and maintainability, and also make it easier to understand the purpose of the components from the name directly, rather than a generic name with a bunch of parameters!

This question isn't just about buttons, but this design decision of why Jetpack Compose offers multiple composable functions for different visual styles, rather than providing a single base composable function that can be customized with style parameters.

Because in the end, if we see the code of these components, you will see it is calling the base components with just different parameters:

@Composable
fun OutlinedButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    shape: Shape = ButtonDefaults.outlinedShape,
    colors: ButtonColors = ButtonDefaults.outlinedButtonColors(),
    elevation: ButtonElevation? = null,
    border: BorderStroke? = ButtonDefaults.outlinedButtonBorder,
    contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    content: @Composable RowScope.() -> Unit
) =
    Button(
        onClick = onClick,
        modifier = modifier,
        enabled = enabled,
        shape = shape,
        colors = colors,
        elevation = elevation,
        border = border,
        contentPadding = contentPadding,
        interactionSource = interactionSource,
        content = content
    )
like image 926
Younes Charfaoui Avatar asked Aug 13 '26 06:08

Younes Charfaoui


1 Answers

Material design components exist not only for Compose, but for Views, Web, Flutter, and as a design principle.

Because of that they are not just styles but Components with each own guidelines, rationale and purposes to create a design style with both M2 and M3.

enter image description here

enter image description here

enter image description here

https://m3.material.io/components/all-buttons

like image 72
Thracian Avatar answered Aug 15 '26 21:08

Thracian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!