Slide 1

Slide 1 text

Advanced Design Pa tt erns with ConstraintLayout 2.1 John Hoford @johnhoford Nicolas Roard @camaelon

Slide 2

Slide 2 text

Overview

Slide 3

Slide 3 text

ConstraintLayout 1.0 • Flexible Layout Manager • Positions relatively, in percentage, as a set (chain) • Dimensions : ratio, percentage, weight… • Helpers : Guideline, Barriers… • ConstraintSet : build your layout rules on the fl y, swap them • Layout Editor

Slide 4

Slide 4 text

ConstraintLayout 2.0 • Virtual Layouts • Helpers & Decorators • Programming APIs • MotionLayout • Motion Editor

Slide 5

Slide 5 text

ConstraintLayout 2.1 • Scalability • View Transitions • Rotation • Motion Helpers • Foldable Support

Slide 6

Slide 6 text

ConstraintLayout 1.0

Slide 7

Slide 7 text

ConstraintLayout 1.0 Compose

Slide 8

Slide 8 text

ConstraintLayout 1.0 • Kotlin DSL for constraints • ConstraintSet support • JSON support • MotionLayout light Compose

Slide 9

Slide 9 text

2.1

Slide 10

Slide 10 text

Scalability 
 MotionScene fi les are getting large!

Slide 11

Slide 11 text

Scalability • Includes - Support separate ConstraintSet fi les • ConstraintOverlay - compact way of modifying derived constraints • ViewTransitions - Dynamic mutation of state

Slide 12

Slide 12 text

• ConstraintSet can now be in separate fi les • Referenced through includes
 • Or directly in Transitions
 motion:constraintSetEnd="@xml/main_scene "

Slide 13

Slide 13 text

• Only need to specify the id and the attributes to change

Slide 14

Slide 14 text

• Operates on one or more views • Can modify the current state

Slide 15

Slide 15 text

• Operates on one or more views • Can modify all ConstraintSets

Slide 16

Slide 16 text

• Can modify all noState These can run asynchronous

Slide 17

Slide 17 text

• Can modify all noState These can run asynchronous

Slide 18

Slide 18 text

Rotation

Slide 19

Slide 19 text

Rotation ConstraintLayout Relative Position 45° 80dp 30dp 135°

Slide 20

Slide 20 text

Rotation ConstraintLayout Relative Position • Changing values in motion Layout

Slide 21

Slide 21 text

Rotation ConstraintLayout Relative Position • Changing values in motion Layout

Slide 22

Slide 22 text

Rotation Polar Mode

Slide 23

Slide 23 text

Rotation Polar Mode

Slide 24

Slide 24 text

Rotation Polar Mode • Setting layout_constraintCircleAngle
 is understood by the polar mode 
 app:layout_constraintCircleAngle. ="360"

Slide 25

Slide 25 text

Rotation Polar Mode • Setting layout_constraintCircleAngle
 is understood by the polar mode 
 app:layout_constraintCircleAngle. ="360"

Slide 26

Slide 26 text

Rotation Polar Mode • They chain 
 moon relative to earth
 earth relative to sun

Slide 27

Slide 27 text

Rotation Polar Mode • They chain 
 moon relative to earth
 earth relative to sun

Slide 28

Slide 28 text

Rotation Polar Mode KeyPosition In Polar mode • KeyPosition works in polar
 percentX is radial change
 percentY is in Angular change

Slide 29

Slide 29 text

Rotation Polar Mode KeyPosition In Polar mode • KeyPosition works in polar
 percentX is radial change
 percentY is in Angular change

Slide 30

Slide 30 text

Rotation Polar Mode KeyPosition In Polar mode • Rocket maintains orbit
 Then moves out to the moon

Slide 31

Slide 31 text

Rotation Polar Mode KeyPosition In Polar mode • Rocket maintains orbit
 Then moves out to the moon

Slide 32

Slide 32 text

• KeyPosition 
 percentX maintains radial distance
 percentY locks the rotation % Rotation Polar Mode KeyPosition In Polar mode

Slide 33

Slide 33 text

• KeyPosition 
 percentX maintains radial distance
 percentY locks the rotation % Rotation Polar Mode KeyPosition In Polar mode

Slide 34

Slide 34 text

• OnSwipe now support rotation via:
 dragDirection , anchorTarget, rotationCenterId • Transform Pivot target can be center of a view Rotation OnSwipe Rotational support

Slide 35

Slide 35 text

• OnSwipe now support rotation via:
 dragDirection , anchorTarget, rotationCenterId • Transform Pivot target can be center of a view Rotation OnSwipe Rotational support

Slide 36

Slide 36 text

Miscellaneous

Slide 37

Slide 37 text

Quantized Motion

Slide 38

Slide 38 text

Quantized Motion

Slide 39

Slide 39 text

Animated Text MotionLabel

Slide 40

Slide 40 text

Animated Text MotionLabel

Slide 41

Slide 41 text

Springs!

Slide 42

Slide 42 text

Springs!

Slide 43

Slide 43 text

Many new api • Programatic addition of Transitions • applyViewTransition() run a view Transitions • scheduleTransitionTo() After completing current transition go next one • updateStateAnimate() - modi fi ed version of current constraintSet animated • transitionToState(…,duration) - transition over a fi xed duration

Slide 44

Slide 44 text

Motion Helpers

Slide 45

Slide 45 text

MotionE ff ect

Slide 46

Slide 46 text

MotionE ff ect

Slide 47

Slide 47 text

MotionE ff ect

Slide 48

Slide 48 text

MotionE ff ect

Slide 49

Slide 49 text

MotionE ff ect + ViewTransition

Slide 50

Slide 50 text

MotionE ff ect + ViewTransition

Slide 51

Slide 51 text

Carousel h tt ps://developer.android.com/training/constraint-layout/motionlayout/carousel

Slide 52

Slide 52 text

Carousel h tt ps://developer.android.com/training/constraint-layout/motionlayout/carousel

Slide 53

Slide 53 text

Foldable support

Slide 54

Slide 54 text

Foldable Support • https://developer.android.com/training/constraint-layout/foldables

Slide 55

Slide 55 text

Foldable Support • https://developer.android.com/training/constraint-layout/foldables

Slide 56

Slide 56 text

Compose

Slide 57

Slide 57 text

ConstraintLayout / Compose • Share code with existing implementation • Kotlin DSL to express constraints • JSON syntax to express constraints • Work in Progress : we want your feedback!

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Variables: { angle: { from: 0, step: 10 }, rotation: { from: 'startRotation', step: 10 }, distance: 100, mylist: { tag: 'box' } }, Generate: { mylist: { width: 200, height: 40, circular: ['parent', 'angle', 'distance'], pivotX: 0.1, pivotY: 0.1, translationX: 225, rotationZ: 'rotation' } }

Slide 66

Slide 66 text

Variables: { angle: { from: 0, step: 10 }, rotation: { from: 'startRotation', step: 10 }, distance: 100, mylist: { tag: 'box' } }, Generate: { mylist: { width: 200, height: 40, circular: ['parent', 'angle', 'distance'], pivotX: 0.1, pivotY: 0.1, translationX: 225, rotationZ: 'rotation' } }

Slide 67

Slide 67 text

MotionLayout / Compose • 2 ConstraintSets or a single MotionScene in JSON • “Light” • No support for touch • No support for multi-states • Check examples • https://github.com/androidx/constraintlayout/tree/main/ projects/ComposeConstraintLayout

Slide 68

Slide 68 text

Link

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Where we are now

Slide 72

Slide 72 text

ConstraintLayout 2.1.0-rc01 dependencies { implementation ‘androidx.constraintlayout:constraintlayout:2.1.0-rc01 ’ } h tt ps://github.com/AndroidX/constraintlayout

Slide 73

Slide 73 text

ConstraintLayout Compose 1.0.0-beta01 dependencies { implementation ‘androidx.constraintlayout:constraintlayout-compose:1.0.0-beta01 ’ } h tt ps://github.com/AndroidX/constraintlayout

Slide 74

Slide 74 text

Give us feedback! https://github.com/androidx/constraintlayout/issues

Slide 75

Slide 75 text

Thanks! John Hoford @johnhoford Nicolas Roard @camaelon