Slide 1

Slide 1 text

Chaining Compose modi iers beyond intuition Meike Felicia Hammer @feliciaf_aye Android Lead @ adesso mobile solutions GmbH

Slide 2

Slide 2 text

Modi iers • size, layout, behaviour, appearance • additional information • user input • clickable, scrollable, draggable, zoomable Decorate and augment composables. Moulding them the way you need them.

Slide 3

Slide 3 text

Chaining all at once? Does the order matter? Photo by Mae Mu on Unsplash

Slide 4

Slide 4 text

Beyond intuition 2 Borders, 1 Padding, 1 Size

Slide 5

Slide 5 text

Modi iers 2 Borders, 1 Padding, 1 Size

Slide 6

Slide 6 text

Beyond intuition 2 Size Modi iers

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

What would happen, when we use size and requiredSize modi iers chained? Force Required Size?

Slide 9

Slide 9 text

The layout node is still illing max size. Also respecting the requiredSize of 50.dp. Force Required Size?

Slide 10

Slide 10 text

How to tackle this? Learn about constraints and the layout phase.

Slide 11

Slide 11 text

Compose Phases Composition What to show Layout Where to place it Drawing How to render it Data Composition Drawing UI Layout size requiredSize padding illMaxSize sizeIn wrapContentSize clip drawBehind rotate scale

Slide 12

Slide 12 text

Layout phase 3 steps to remember • Measure children • Decide own size • Place children Constraints help inding the right size in the irst two steps.

Slide 13

Slide 13 text

Constraints are the min and max bounds for the size of a node. H W ( x , y ) De inition

Slide 14

Slide 14 text

What kind of constraints do we have?

Slide 15

Slide 15 text

Bounded constraints Layout node has to choose a width between 100 and 400 and a height between 100 and 400. 100 - 400 100 - 400

Slide 16

Slide 16 text

Unbounded constraints The node is not constraint to any size. The maximum width and height bounds are set to in inity. 0 - ∞ 0 - ∞

Slide 17

Slide 17 text

Exact constraints Layout node should have an exact size. The minimum and maximum bounds have the same size. 300 - 300 200 - 200

Slide 18

Slide 18 text

Combined constraints Bounding width, providing an unbounded maximum height. Exact width, providing a bounded height. 600 - 600 0 - 400 100 - 400 100 - ∞

Slide 19

Slide 19 text

Constraints in Action Constraints are passed down from parent to child in the UI Tree during the layout phase. Parent measures it’s child. When a node has measured its own size, it communicates it’s size back up to the tree.

Slide 20

Slide 20 text

UI Tree SIZE CONSTRAINTS IMAGE ROTATE (90) SIZE (46) COLUMN PADDING (start = 16) BUTTON ROW PADDING (top = 16) BUTTON

Slide 21

Slide 21 text

600 300 IMAGE ROTATE (90) SIZE (100) COLUMN PADDING (start = 16) BUTTON Text: 119*82 ROW PADDING (top = 16) BUTTON Text: 140*82 Traversing w: 0 - 600 h: 0 - 300 w: 0 - 600 h: 0 - 300 w: 0 - 584 h: 0 - 300 BUTTON w: 0 - 584 h: 0 - 202 BTN w: 0 - 444 h: 0 - 300 W: 256, H: 180 <— Max —> <— SUM —> w: 256 h: 180 w: 0 - 584 h: 0 - 300 w: 140 h: 98 w: 119 h: 82 w: 140 h: 180 w: 100 h: 100 w: 156 h: 180

Slide 22

Slide 22 text

Too big Out of range IMAGE SIZE (600) IMAGE SIZE (80) Too small w: 100 - 200 h: 100 - 500 w: 100 - 200 h: 100 - 500 w: 200 - 200 h: 500 - 500 Adapting as closely as it can. w: 100 - 100 h: 100 - 100 Respecting the incoming bounds.

Slide 23

Slide 23 text

Constraints affect the size of composables. Modi iers affect constraints. What is the relation between constraints and modi iers? Constraint vs Modi ier

Slide 24

Slide 24 text

Padding - Background - Border Intuitive Sample

Slide 25

Slide 25 text

Padding - Background - Border

Slide 26

Slide 26 text

Beyond intuition Scale - Offset

Slide 27

Slide 27 text

Sample Scale - Offset Scaled and then moved to the right. Moves to the right before scaling.

Slide 28

Slide 28 text

Sample Scale - Offset

Slide 29

Slide 29 text

Beyond intuition Custom Modi ier

Slide 30

Slide 30 text

Custom Modi ier Custom Modi ier + Clip Clip + Custom Modi ier

Slide 31

Slide 31 text

Custom Modi ier Custom Modi ier + Clip Clip + Custom Modi ier

Slide 32

Slide 32 text

In luencing size, shape and behaviour of composables • Usually read top to bottom • Counter-intuitive regarding some cases • Some modi iers are ineffective applied multiple times ORDER MATTERS

Slide 33

Slide 33 text

Meike F. Hammer @feliciaf_aye Chaining Compose modi iers beyond intuition Android Lead @ adesso mobile solutions GmbH THANK YOU WE ARE HIRING