Slide 1

Slide 1 text

Production MotionLayout Jason Pearson NYC Android Developers Meetup - Jan 2020

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

@layout/activity_main Creating our first MotionScene @kaeawc

Slide 5

Slide 5 text

@layout/activity_main Creating our first MotionScene @layout/activity_main @kaeawc

Slide 6

Slide 6 text

@layout/activity_main Creating our first MotionScene Need to create a MotionScene @layout/activity_main @kaeawc

Slide 7

Slide 7 text

src/ ├── java/ └── res/ ├── drawable ├── layout │ └── ├── mipmap └── values Creating our first MotionScene activity_main.xml @kaeawc

Slide 8

Slide 8 text

Creating our first MotionScene src/ ├── java/ └── res/ ├── drawable ├── layout │ └── ├── mipmap ├── values └── xml activity_main.xml @kaeawc

Slide 9

Slide 9 text

src/ ├── java/ └── res/ ├── drawable ├── layout │ └── ├── mipmap ├── values └── xml └── motion_scene.xml activity_main.xml Creating our first MotionScene xml motion_scene @kaeawc

Slide 10

Slide 10 text

@xml/motion_scene Creating our first MotionScene motion_scene xml @kaeawc

Slide 11

Slide 11 text

@xml/motion_scene @layout/activity_main Creating our first MotionScene @layout/activity_main

Slide 12

Slide 12 text

@xml/motion_scene @layout/activity_main Creating our first MotionScene @layout/activity_main

Slide 13

Slide 13 text

@xml/motion_scene @layout/activity_main Creating our first MotionScene @layout/activity_main

Slide 14

Slide 14 text

@layout/activity_main @layout/activity_main Creating our first MotionScene @xml/motion_scene

Slide 15

Slide 15 text

@layout/activity_main Adding first child to MotionScene @kaeawc

Slide 16

Slide 16 text

@layout/activity_main Adding first child to MotionScene @kaeawc

Slide 17

Slide 17 text

@xml/motion_scene Adding first ConstraintSet @kaeawc

Slide 18

Slide 18 text

@xml/motion_scene Adding first ConstraintSet @kaeawc

Slide 19

Slide 19 text

@xml/motion_scene Adding first ConstraintSet Omitting schemas from now on @kaeawc

Slide 20

Slide 20 text

@xml/motion_scene Adding first ConstraintSet @kaeawc

Slide 21

Slide 21 text

@xml/motion_scene Adding first ConstraintSet @xml/motion_scene @kaeawc

Slide 22

Slide 22 text

@xml/motion_scene Adding first ConstraintSet @xml/motion_scene motion_scene.xml ConstraintSet start @kaeawc

Slide 23

Slide 23 text

Adding second ConstraintSet @xml/motion_scene motion_scene.xml ConstraintSet start @kaeawc

Slide 24

Slide 24 text

Adding second ConstraintSet @xml/motion_scene motion_scene.xml ConstraintSet start ConstraintSet end @kaeawc

Slide 25

Slide 25 text

Adding second ConstraintSet @xml/motion_scene motion_scene.xml ConstraintSet start ConstraintSet end @kaeawc

Slide 26

Slide 26 text

Adding second ConstraintSet @xml/motion_scene motion_scene.xml ConstraintSet start ConstraintSet end @kaeawc

Slide 27

Slide 27 text

@xml/motion_scene

Slide 28

Slide 28 text

@xml/motion_scene

Slide 29

Slide 29 text

@xml/motion_scene Adding first Transition @xml/motion_scene motion_scene.xml ConstraintSet start ConstraintSet end Transition start @kaeawc

Slide 30

Slide 30 text

@xml/motion_scene Adding first Transition @xml/motion_scene motion_scene.xml ConstraintSet start ConstraintSet end Transition start end @kaeawc

Slide 31

Slide 31 text

@xml/motion_scene

Slide 32

Slide 32 text

@xml/motion_scene

Slide 33

Slide 33 text

@xml/motion_scene

Slide 34

Slide 34 text

@xml/motion_scene

Slide 35

Slide 35 text

motion_scene.xml It works! " ConstraintSet start ConstraintSet end Transition OnClick square start end @kaeawc

Slide 36

Slide 36 text

@xml/motion_scene motion_scene.xml @xml/motion_scene ConstraintSet start ConstraintSet end OnClick Transition OnClick square start end @kaeawc

Slide 37

Slide 37 text

@xml/motion_scene motion_scene.xml @xml/motion_scene ConstraintSet start ConstraintSet end OnClick Transition OnClick square start end @kaeawc

Slide 38

Slide 38 text

@xml/motion_scene OnClick motion_scene.xml ConstraintSet start ConstraintSet end Transition OnClick square start end @kaeawc

Slide 39

Slide 39 text

OnClick motion_scene_with_click.xml Transition OnClick square start end ConstraintSet start ConstraintSet end @kaeawc

Slide 40

Slide 40 text

motion_scene_with_click.xml motion_scene_with_swipe.xml OnSwipe OnClick ConstraintSet start ConstraintSet end Transition OnClick square start end Transition OnSwipe square start end start end ConstraintSet start ConstraintSet end @kaeawc

Slide 41

Slide 41 text

Transition OnClick square start Transition end OnSwipe square start end OnSwipe OnClick @kaeawc

Slide 42

Slide 42 text

@xml/motion_scene_with_swipe @xml/motion_scene_with_click @xml/motion_scene_with_click @xml/motion_scene_with_swipe OnSwipe OnClick @kaeawc

Slide 43

Slide 43 text

@xml/motion_scene_with_swipe @xml/motion_scene_with_click OnSwipe OnClick @xml/motion_scene_with_click @xml/motion_scene_with_swipe @kaeawc

Slide 44

Slide 44 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 45

Slide 45 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 46

Slide 46 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 47

Slide 47 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 48

Slide 48 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 49

Slide 49 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 50

Slide 50 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 51

Slide 51 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 52

Slide 52 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 53

Slide 53 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 54

Slide 54 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 55

Slide 55 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 56

Slide 56 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 57

Slide 57 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 58

Slide 58 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 59

Slide 59 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 60

Slide 60 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 61

Slide 61 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 62

Slide 62 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 63

Slide 63 text

OnSwipe @xml/motion_scene_with_swipe @kaeawc

Slide 64

Slide 64 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 65

Slide 65 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 66

Slide 66 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 67

Slide 67 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 68

Slide 68 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 69

Slide 69 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 70

Slide 70 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 71

Slide 71 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 72

Slide 72 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 73

Slide 73 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 74

Slide 74 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 75

Slide 75 text

@xml/motion_scene_with_swipe OnSwipe @kaeawc

Slide 76

Slide 76 text

autoComplete stop decelerate @kaeawc

Slide 77

Slide 77 text

@xml/swiping_scene Adding another state swiping_scene.xml ConstraintSet start ConstraintSet end @kaeawc

Slide 78

Slide 78 text

@xml/swiping_scene Adding another state swiping_scene.xml ConstraintSet start ConstraintSet end ConstraintSet middle @kaeawc

Slide 79

Slide 79 text

@xml/swiping_scene Adding another state swiping_scene.xml ConstraintSet start Transition swipe_a OnSwipe square start middle Transition swipe_b OnSwipe square middle end @kaeawc

Slide 80

Slide 80 text

Adding another state swiping_scene.xml ConstraintSet start ConstraintSet end ConstraintSet middle Transition swipe_a OnSwipe square start middle Transition swipe_b OnSwipe square middle end

Slide 81

Slide 81 text

@xml/motion_scene @xml/motion_scene Interpolation @kaeawc

Slide 82

Slide 82 text

easeInOut easeIn easeOut linear standard bounce cubic @xml/motion_scene Interpolation @kaeawc

Slide 83

Slide 83 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 84

Slide 84 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 85

Slide 85 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 86

Slide 86 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 87

Slide 87 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 88

Slide 88 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 89

Slide 89 text

easeInOut easeIn easeOut linear standard bounce cubic(0.42,0,1,1) app:motionInterpolator=" "a Interpolation @kaeawc

Slide 90

Slide 90 text

app:motionInterpolator="cubic(0.42,0,1,1)" https://cubic-bezier.com/#.42,0,1,1 Interpolation @kaeawc

Slide 91

Slide 91 text

Interpolation app:motionInterpolator="cubic(0.42,0,1,1)" https://cubic-bezier.com/#.42,0,1,1 @kaeawc

Slide 92

Slide 92 text

https://cubic-bezier.com/#.42,0,1,1

Slide 93

Slide 93 text

Sub Elements @kaeawc

Slide 94

Slide 94 text

Sub Elements @kaeawc

Slide 95

Slide 95 text

Sub Elements @kaeawc

Slide 96

Slide 96 text

Sub Elements :-PropertySet @kaeawc

Slide 97

Slide 97 text

Sub Elements :-PropertySet @kaeawc

Slide 98

Slide 98 text

Sub Elements :-Motion @kaeawc

Slide 99

Slide 99 text

Linear Horizontal Vertical @kaeawc

Slide 100

Slide 100 text

Horizontal Linear Vertical @kaeawc

Slide 101

Slide 101 text

@xml/motion_scene @xml/motion_scene Sub Elements :-Motion @kaeawc

Slide 102

Slide 102 text

Sub Elements :-Motion @xml/motion_scene @kaeawc

Slide 103

Slide 103 text

Sub Elements: Transform @kaeawc

Slide 104

Slide 104 text

swiping_scene.xml Sub Elements: Transform ConstraintSet start ConstraintSet end Transition toggle OnClick square start end @kaeawc

Slide 105

Slide 105 text

swiping_scene.xml Sub Elements: Transform ConstraintSet start ConstraintSet end Transition toggle OnClick square start end Transform @kaeawc

Slide 106

Slide 106 text

swiping_scene.xml Sub Elements: Transform ConstraintSet start ConstraintSet end Transition toggle OnClick square start end Transform rotate 360 @kaeawc

Slide 107

Slide 107 text

swiping_scene.xml Sub Elements: Transform ConstraintSet start ConstraintSet end Transition toggle OnClick square start end Transform rotate 360 rotateX 360 @kaeawc

Slide 108

Slide 108 text

swiping_scene.xml Sub Elements: Transform ConstraintSet start ConstraintSet end Transition toggle OnClick square start end Transform rotate 360 rotateX 360 @kaeawc

Slide 109

Slide 109 text

Sub Elements: Transform swiping_scene.xml ConstraintSet start ConstraintSet end Transition toggle OnClick square start end Transform rotate 360 rotateX 360 @kaeawc

Slide 110

Slide 110 text

Sub Elements: Transform swiping_scene.xml ConstraintSet start ConstraintSet end Transition toggle OnClick square start end KeyFrameSet Transform rotate 360 rotateX 360 @kaeawc

Slide 111

Slide 111 text

Sub Elements: Transform swiping_scene.xml ConstraintSet start ConstraintSet end Transition toggle OnClick square start end KeyFrameSet KeyFrame 33 KeyFrame 66 translateX -64dp translateX 64dp Transform rotate 360 rotateX 360 @kaeawc

Slide 112

Slide 112 text

KeyFrameSet Sub Elements: Transform swiping_scene.xml ConstraintSet start ConstraintSet end Transition toggle OnClick square start end KeyFrameSet KeyFrame 33 KeyFrame 66 translateX -64dp translateX 64dp Transform rotate 360 rotateX 360 @kaeawc

Slide 113

Slide 113 text

KeyFrameSet KeyFrameSets @kaeawc

Slide 114

Slide 114 text

KeyFrameSet KeyFrameSets @kaeawc

Slide 115

Slide 115 text

KeyFrameSets KeyFrameSet KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 116

Slide 116 text

KeyFrameSets KeyFrameSet KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 117

Slide 117 text

KeyFrameSets KeyFrameSet 100 0 25 50 75 KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 118

Slide 118 text

KeyFrameSets KeyFrameSet 100 0 25 50 75 KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 119

Slide 119 text

KeyFrameSets KeyFrameSet 100 0 25 50 75 KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 120

Slide 120 text

KeyFrameSets KeyFrameSet 100 0 25 50 75 KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 121

Slide 121 text

KeyFrameSets KeyFrameSet 100 0 25 50 75 KeyFrames let you specify a change at a point in time during transition @kaeawc

Slide 122

Slide 122 text

KeyFrameSets: Key Attribute @kaeawc

Slide 123

Slide 123 text

KeyFrameSets: Key Attribute @kaeawc

Slide 124

Slide 124 text

KeyFrameSets: Key Attribute @kaeawc

Slide 125

Slide 125 text

KeyFrameSets: Key Attribute @kaeawc

Slide 126

Slide 126 text

KeyFrameSets: Key Attribute @kaeawc

Slide 127

Slide 127 text

KeyFrameSets: Key Attribute @kaeawc

Slide 128

Slide 128 text

Practical Examples

Slide 129

Slide 129 text

Swipe To Reveal Action in a List @layout/activity_swipe_items @kaeawc

Slide 130

Slide 130 text

@layout/activity_swipe_items Swipe To Reveal Action in a List @kaeawc

Slide 131

Slide 131 text

@layout/activity_swipe_items @xml/swipe_item_scene Swipe To Reveal Action in a List @kaeawc

Slide 132

Slide 132 text

@xml/swipe_item_scene Swipe To Reveal Action in a List @kaeawc

Slide 133

Slide 133 text

@xml/swipe_item_scene Swipe To Reveal Action in a List @kaeawc

Slide 134

Slide 134 text

@xml/swipe_item_scene Swipe To Reveal Action in a List @kaeawc

Slide 135

Slide 135 text

Swipe To Reveal @kaeawc

Slide 136

Slide 136 text

Swipe To Reveal @kaeawc

Slide 137

Slide 137 text

Swipe To Reveal @kaeawc

Slide 138

Slide 138 text

There is no change in horizontal position of any side in the foreground view, therefore MotionLayout cannot determine how to interpolate between the two states Swipe To Reveal @kaeawc

Slide 139

Slide 139 text

Swipe To Reveal @kaeawc

Slide 140

Slide 140 text

Swipe To Reveal @kaeawc

Slide 141

Slide 141 text

Swipe To Reveal @kaeawc

Slide 142

Slide 142 text

Swipe To Reveal @kaeawc

Slide 143

Slide 143 text

Swipe To Reveal @kaeawc

Slide 144

Slide 144 text

Swipe To Reveal Action in a List @kaeawc

Slide 145

Slide 145 text

Or do not specify a touchAnchor and then there is no need to create clever hidden views. Swipe To Reveal Action in a List @kaeawc

Slide 146

Slide 146 text

Collapsing Toolbar @layout/activity_collapsing_toolbar @kaeawc

Slide 147

Slide 147 text

Collapsing Toolbar @xml/collapse_on_scroll_scene @kaeawc

Slide 148

Slide 148 text

Collapsing Toolbar @xml/collapse_on_scroll_scene @kaeawc

Slide 149

Slide 149 text

Slide 150

Slide 150 text

android:layout_height="128dp" app:layout_constraintTop_toTopOf="parent"/> Collapsing Toolbar @xml/collapse_on_scroll_scene @kaeawc

Slide 151

Slide 151 text

android:layout_height="128dp" app:layout_constraintTop_toTopOf="parent"/> Collapsing Toolbar - Derived Constraints @xml/collapse_on_scroll_scene @kaeawc

Slide 152

Slide 152 text

Nested MotionLayout @kaeawc

Slide 153

Slide 153 text

@layout/activity_collapsing_toolbar Nested MotionLayout @layout/activity_collapsing_toolbar @kaeawc

Slide 154

Slide 154 text

@layout/activity_collapsing_toolbar Nested MotionLayout @layout/activity_collapsing_toolbar @kaeawc

Slide 155

Slide 155 text

Nested MotionLayout Header - Scaling Text @xml/collapsing_header_scene @kaeawc

Slide 156

Slide 156 text

@xml/collapsing_header_scene Nested MotionLayout Header - Scaling Text @kaeawc

Slide 157

Slide 157 text

Scaling Text @kaeawc

Slide 158

Slide 158 text

Scaling Text @kaeawc

Slide 159

Slide 159 text

Scaling Text @kaeawc

Slide 160

Slide 160 text

textSize via CustomAttribute scaleX&Y via Transform @kaeawc

Slide 161

Slide 161 text

Nested MotionLayout Header @xml/collapsing_header_scene @kaeawc

Slide 162

Slide 162 text

Slide 163

Slide 163 text

Slide 164

Slide 164 text

Nested MotionLayout @xml/collapse_on_scroll_scene @kaeawc

Slide 165

Slide 165 text

Nested MotionLayout @xml/collapse_on_scroll_scene @kaeawc

Slide 166

Slide 166 text

Nested MotionLayout @xml/collapse_on_scroll_scene @kaeawc

Slide 167

Slide 167 text

Slide 168

Slide 168 text

tionScene> Changing Text in MotionLayout @xml/collapsing_header_scene @kaeawc

Slide 169

Slide 169 text

Slide 170

Slide 170 text

Slide 171

Slide 171 text

Slide 172

Slide 172 text

Changing Constraints Programmatically • MotionLayout is just an extension of ConstraintLayout • After making changes to a ConstraintSet we must call motionLayout.updateState(constraintSetId, constraintSet) motionLayout.setTransition(start, end) motionLayout.transitionToEnd() @kaeawc

Slide 173

Slide 173 text

constraintSet.connect(viewId, TOP, R.id.boundaries, TOP, 0) constraintSet.connect(viewId, START, R.id.boundaries, START, 0) constraintSet.connect(viewId, END, R.id.boundaries, END, 0) constraintSet.connect(viewId, BOTTOM, R.id.boundaries, BOTTOM, 0) constraintSet.setElevation(view.id, 1f) motion_layout.updateState(R.id.zoomed_in, constraintSet) Changing Constraints Programmatically PhotoGridActivity.kt @xml/grid_zoom_scene @kaeawc

Slide 174

Slide 174 text

RecyclerView & MotionLayout Placeholder • Calculate ViewHolder View position • Update a placeholder view within the starting ConstraintSet • Show hidden MotionLayout with placeholder @kaeawc

Slide 175

Slide 175 text

RecyclerView & MotionLayout Placeholder @kaeawc

Slide 176

Slide 176 text

AutoTransitions @kaeawc

Slide 177

Slide 177 text

Changing Transitions on the fly

Slide 178

Slide 178 text

No content

Slide 179

Slide 179 text

Constraints - Limitations • Some problems cannot be solved with derived Constraints. • Creating a very large number of ConstraintSets and Transitions is infeasible. @kaeawc

Slide 180

Slide 180 text

Constraints - Limitations N!/2 States Each requires a handwritten ConstraintSet This 2x2 board has 12 states A 3x3 board would have 181440 states @kaeawc

Slide 181

Slide 181 text

Constraints - Limitations @kaeawc

Slide 182

Slide 182 text

Other Practical Examples

Slide 183

Slide 183 text

Swiping Items with Collapsing Toolbar @kaeawc

Slide 184

Slide 184 text

Progress Indicator @kaeawc

Slide 185

Slide 185 text

ProgressBar @kaeawc

Slide 186

Slide 186 text

TabLayout & Many NestedScrollViews MainActivity.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) view_pager?.apply { adapter = MainAdapter(supportFragmentManager) tab_layout?.setupWithViewPager(this) addOnPageChangeListener(object: ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) {} override fun onPageScrolled(...) {} override fun onPageSelected(position: Int) { if (root_layout?.progress != 0f) { root_layout?.transitionToStart() } } }) } } internal fun onVerticalScroll(scroll: Int) { root_layout?.progress = Math.min(scroll / 1000f, 1f) } @kaeawc

Slide 187

Slide 187 text

Summary

Slide 188

Slide 188 text

Why You Should Try MotionLayout • Reduces context switching • Makes some hard animations much easier • Allows us to make animations reentrant, continuous, & smooth @kaeawc

Slide 189

Slide 189 text

Challenges in using MotionLayout • It’s still in beta • Lack of official learning materials • Debugging is a bit of trial and error https://codelabs.developers.google.com/codelabs/motion-layout/ But its so much easier now with MotionEditor @kaeawc

Slide 190

Slide 190 text

11 MotionLayout in Hinge's production app Onboarding Flow @kaeawc

Slide 191

Slide 191 text

Questions? 11 MotionLayout in Hinge's production app Profile Flows @kaeawc

Slide 192

Slide 192 text

Questions? bit.ly/prod-motionlayout-nyc-meetup-jan-2020 find me on Twitter / Github @kaeawc