Slide 1

Slide 1 text

Introduction to Motion Layout Saurabh Arora Rakuten Viki @saurabh_arora90

Slide 2

Slide 2 text

Dev asked to work on animations

Slide 3

Slide 3 text

Devs after motion layout

Slide 4

Slide 4 text

Constraint Layout ● Complex layouts with a flat hierarchy ● Specifying constraints on views w.r.t other views ● Helpers such as Barriers, Groups & Guidelines

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Constraint Set ● Create another layout file with end state ● Pick constraints from end state layout file ● Apply constraints to constraint layout ● Use transition manager for smooth transition

Slide 8

Slide 8 text

private val start: ConstraintSet by lazy { val set = ConstraintSet() set.clone(this, R.layout.start) set }

Slide 9

Slide 9 text

private val start: ConstraintSet by lazy { val set = ConstraintSet() set.clone(this, R.layout.start) set } private val end: ConstraintSet by lazy { val set = ConstraintSet() set.clone(this, R.layout.end) set }

Slide 10

Slide 10 text

onClick() { TransitionManager.beginDelayedTransition(layoutRoot) end.applyTo(constraintLayoutRoot) }

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Constraint Set

Slide 13

Slide 13 text

Constraint Set (Cons) ● Uninterruptible ● Multiple Layout files ● Ignores style attributes

Slide 14

Slide 14 text

Motion Layout

Slide 15

Slide 15 text

Motion Layout ● Introduced in ConstraintLayout 2.0 ● Subclass of ConstraintLayout ● Works with touch system ● Support for intermediate states (keyframes) ● Fully declarative

Slide 16

Slide 16 text

.......

Slide 17

Slide 17 text

.......

Slide 18

Slide 18 text

.......

Slide 19

Slide 19 text

Motion Scene Constraint Set Transition Constraints Attributes OnClick OnSwipe KeyFrame Set KeyPosition KeyAttribute

Slide 20

Slide 20 text

Attribute Constraint Layout Params Standard Attributes Visibility Alpha Custom Attributes Elevation Scale Rotation Translation ● Reflection ● String, color, float,int or boolean

Slide 21

Slide 21 text

Examples

Slide 22

Slide 22 text

01: Migrate from Constraint Set​

Slide 23

Slide 23 text

private val start: ConstraintSet by lazy { val set = ConstraintSet() set.clone(this, R.layout.start) set } private val end: ConstraintSet by lazy { val set = ConstraintSet() set.clone(this, R.layout.end) set } ....... TransitionManager.beginDelayedTransition(layoutRoot) end.applyTo(layoutRoot)

Slide 24

Slide 24 text

.......

Slide 25

Slide 25 text

.......

Slide 26

Slide 26 text

.......

Slide 27

Slide 27 text

Slide 28

Slide 28 text

Slide 29

Slide 29 text

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Slide 32

Slide 32 text

02: Self Contained Scene

Slide 33

Slide 33 text

Slide 34

Slide 34 text

Slide 35

Slide 35 text

..... ....

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

....

Slide 38

Slide 38 text

....

Slide 39

Slide 39 text

03: Attributes

Slide 40

Slide 40 text

Attribute Constraint Layout Params Standard Attributes Visibility Alpha Custom Attributes Elevation Scale Rotation Translation ● Reflection ● String, color, float,int or boolean

Slide 41

Slide 41 text

Custom Attributes ● Call "set"Name method via reflection ● Case sensitive. ● Supports color, string, int, float, boolean & dimension

Slide 42

Slide 42 text

Slide 43

Slide 43 text

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

04. Keyframes

Slide 46

Slide 46 text

Motion Scene Constraint Set Transition Constraints Attributes OnClick OnSwipe KeyFrame Set KeyPosition KeyAttribute

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Slide 49

Slide 49 text

Slide 50

Slide 50 text

Slide 51

Slide 51 text

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Motion Scene Constraint Set Transition Constraints Attributes OnClick OnSwipe KeyFrame Set KeyPosition KeyAttribute

Slide 54

Slide 54 text

Slide 55

Slide 55 text

Slide 56

Slide 56 text

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Slide 59

Slide 59 text

05: Motion Progress

Slide 60

Slide 60 text

}ViewPager

Slide 61

Slide 61 text

viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { })

Slide 62

Slide 62 text

viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { override fun onPageScrolled(pos: Int, offset: Float, pixels: Int) { } })

Slide 63

Slide 63 text

viewPager.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() { override fun onPageScrolled(pos: Int, offset: Float, pixels: Int) { motionRoot.progress = (position + positionOffset) / (COUNT - 1) } })

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

}RecyclerView }AppBarLayout

Slide 67

Slide 67 text

Slide 68

Slide 68 text

Slide 69

Slide 69 text

............

Slide 70

Slide 70 text

............

Slide 71

Slide 71 text

AppBarLayout.addOnOffsetChangedListener(this) override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) { }

Slide 72

Slide 72 text

AppBarLayout.addOnOffsetChangedListener(this) override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) { progress = -verticalOffset / appBarLayout.totalScrollRange.toFloat() }

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Recap ● Part of constraint layout 2.0 - alpha release ● Works with both position/layout and styling attributes ● Interruptible and can set progress

Slide 75

Slide 75 text

A mix between the property animation framework, layout transitions with TransitionManager, and CoordinatorLayout - Nicolas Roard

Slide 76

Slide 76 text

Devs after motion layout

Slide 77

Slide 77 text

Didn't cover ● States and Variants ● Transition easing ● KeyCycles

Slide 78

Slide 78 text

What’s next ● Better Tooling ● Motion editor

Slide 79

Slide 79 text

Resources ● Google IO'18 Talk ● Introduction to Motion Layout by Nicolas Roard ● Github : MotionLayout-Playground : https://github.com/saurabharora90/MotionLayout-Playground

Slide 80

Slide 80 text

Saurabh Arora, Rakuten VIki @saurabh_arora90 Thank you!

Slide 81

Slide 81 text

Q&A Follow the sli.do link in the hall to ask questions