Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jetpack Compose + design systems

Jetpack Compose + design systems

François Blavoet

May 03, 2022
Tweet

More Decks by François Blavoet

Other Decks in Programming

Transcript

  1. Jetpack Compose • Compose is the future of Android UI

    development • When is the best time to start adopting it ?
  2. Design systems What is a Design system ? -> it

    is a complete set of standards intended to manage design at scale using reusable components and patterns.
  3. Let’s have a look at one component Row.Content { leading(

    label = "Order Changes Preferences", label2 = "Suggest replacements ...", ) trailing( label = "Edit", option = Row.TrailingOption.Clickable(onPreferenceClick) ) }
  4. Let’s have a look at one component Row.Content { leading(

    label = "Tue Jun 2, 4–5pm", option = LeadingOption.Icon(Icon.Time), ) }
  5. Material Design Button( onClick: () -> Unit, modifier: Modifier =

    Modifier, enabled: Boolean = true, interactionSource: MutableInteractionSource = remember {..}, elevation: ButtonElevation? = ButtonDefaults.elevation(), shape: Shape = MaterialTheme.shapes.small, border: BorderStroke? = null, colors: ButtonColors = ButtonDefaults.buttonColors(), contentPadding: PaddingValues = ButtonDefaults.ContentPadding, content: @Composable RowScope.() -> Unit, )
  6. Atoms Requirements: • Day/night • Customizable for white label apps

    • As easy to use as possible • Have an abstract representation outside of the composition
  7. Atoms interface ColorSpec { @Composable fun value(): Color companion object

    { val SystemGrayscale70: ColorSpec = … val SystemGrayscale50: ColorSpec = … … } }
  8. Atoms interface ColorSpec { @Composable fun value(): Color companion object

    { val SystemGrayscale70: ColorSpec = … val SystemGrayscale50: ColorSpec = … … fun fromColor(color: Color): ColorSpec { return StaticColor(color) } } }
  9. Atoms @Composable fun DesignTheme( configuration: ThemeConfig? = null, content: @Composable

    () -> Unit, ) { … } object DesignTheme { val colors: Colors @Composable @ReadOnlyComposable get() = LocalColors.current }
  10. Atoms interface IconSlot { @Composable fun Content(contentColor: Color) companion object

    { fun fromResource( @DrawableRes res: Int, contentDescription: TextSpec?, ): IconSlot { return ResIcon(res, contentDescription) } } }
  11. Atoms enum class Icons(@DrawableRes internal val resId: Int) : IconSlot

    { Accessibility(R.drawable.cp_accessibility), Account(R.drawable.cp_account), Add(R.drawable.cp_add), … }
  12. Molecules data class PillSpec( val label: TextSpec, val onClick: (()

    -> Unit)?, val selected: Boolean = false, ) @Composable fun Pill( spec: PillSpec, modifier: Modifier = Modifier, )
  13. Molecules data class PillSpec( val label: TextSpec, val onClick: (()

    -> Unit)?, val selected: Boolean = false, ) @Composable fun Pill( spec: PillSpec, modifier: Modifier = Modifier, ) @Composable fun BasePill( selected: Boolean, onClick: (() -> Unit)?, modifier: Modifier = Modifier, … content: @Composable BoxScope.(contentColor: Color) -> Unit, )
  14. Going Further import androidx.compose.material.Text @Composable fun Text( text: AnnotatedString, modifier:

    Modifier = Modifier, style: TextStyle = LocalTextStyle.current, … ) {
  15. 33