Mobile development

Stage 2 · Lesson 3 of 10

Modifiers and why their order matters

Jetpack Compose UI

A changes how a looks or behaves: size, padding, background, border, click handling, scrolling and more. Modifiers are chained and applied in order, from the outside in. So Modifier.padding(16.dp).background(Color.Red) leaves a gap around a red area.

Put background before padding and the padding is coloured too. The same goes for clickable: put it before padding and the whole padded area can be tapped. By convention every reusable composable takes a modifier parameter with a default of Modifier, and applies it to its outermost element. That lets callers position it.

Common trapforgetting that parameter, which makes a component impossible to size or space from the outside.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

Practise

  • Use a free challenge's mobile design image as the spec for a native screen

Keep handy

  • Spacing, type scale, colour and component specs your screens should follow

Mark this stage as not done?