Slide 1

Slide 1 text

Delight users with Motion Layout Saurabh Arora Rakuten Viki @saurabh_arora90

Slide 2

Slide 2 text

Soompi is the world’s largest K-Pop and lifestyle editorial destination for breaking entertainment news, fashion & beauty articles, and exclusive events for international fans of Asian entertainment and culture. Viki is a global video platform, where millions of people watch and engage with their favorite TV shows, Viki Originals, movies, and influencer videos. VIDEO EDITORIAL

Slide 3

Slide 3 text

Delight users with Motion Layout Saurabh Arora Rakuten Viki @saurabh_arora90

Slide 4

Slide 4 text

Dev asked to work on tricky animations

Slide 5

Slide 5 text

Devs after motion layout

Slide 6

Slide 6 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 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Constraint Layout Animations ● Constraint sets ● Start scene and an End scene ● Use transition manager for smooth transition

Slide 10

Slide 10 text

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

Slide 11

Slide 11 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 12

Slide 12 text

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

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Constraint Set

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Motion Layout

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

.......

Slide 19

Slide 19 text

.......

Slide 20

Slide 20 text

.......

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Constrains Layout Params Standard Attributes Visibility Alpha Custom Attributes Elevation Scale Rotation Translation ● Setter ● String, color, float,int or boolean

Slide 23

Slide 23 text

Examples

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

01: Working with Constraints

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

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Slide 33

Slide 33 text

02: Attributes

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

... ...

Slide 36

Slide 36 text

03. Keyframes

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Slide 39

Slide 39 text

Slide 40

Slide 40 text

Slide 41

Slide 41 text

04: Multiple Transitions

Slide 42

Slide 42 text

....

Slide 43

Slide 43 text

05: Motion Progress

Slide 44

Slide 44 text

}ViewPager

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

}RecyclerView }AppBarLayout

Slide 49

Slide 49 text

...

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

06: Other Examples

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Recap ● Part of constraint layout 2.0 ● Works with both position/layout and styling attributes ● Interruptible and can set progress ● Click and Swipe Triggers

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Devs after motion layout

Slide 57

Slide 57 text

Didn't cover ● Auto Transition ● Transition easing ● KeyCycles and KeyTriggers

Slide 58

Slide 58 text

What’s next ● Better Tooling ● Motion editor

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

Saurabh Arora, Rakuten VIki @saurabh_arora90 Thank you!

Slide 61

Slide 61 text

Q&A