Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Material Motion

Intro to Material Motion

Material Motion is a toolkit for building responsive motion using Core Animation.

Learn more at https://github.com/material-motion

View the original deck at https://docs.google.com/presentation/d/1vXNpEYTMCXugFDNNBOWXBtQY9jHsB7FxxYa6BqpUnlM/pub?start=false&loop=false&delayms=3000

featherless

April 10, 2017
Tweet

Other Decks in Programming

Transcript

  1. About @featherless Software designer on the Material Design team I

    build shared libraries for Google’s iOS apps and the open source community
  2. About @featherless Software designer on the Material Design team Previously:

    Facebook iOS app 2009 Nimbus iOS libraries 2011 Google Maps iOS app 2012 Material Components iOS libraries at Google 2013, 2014-2015
  3. Jank is any stuttering, juddering or just plain halting that

    users see when an app isn't keeping up with the refresh rate. - jankfree.org
  4. Gestural interactions should feed their velocity into animations in a

    simulation of continuous momentum. - from Facebook Paper’s tech talk youtu.be/OiY1cheLpmI?t=47m30s
  5. Don’t force users to wait for animations to complete before

    being allowed to take their next action.
  6. Animations don’t generally react well to breakpoints because breakpoints disconnect

    animations from time. We need real-time tooling designed specifically for motion.
  7. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts
  8. Interactions Constraints Intro to Material Motion How to make things

    move How to build transitions Closing thoughts
  9. Interactions Constraints Intro to Material Motion How to make things

    move How to build transitions Closing thoughts
  10. let draggable = Draggable() let rotatable = Rotatable() let scalable

    = Scalable() How to make things move Gestural
  11. // Interaction: Draggable let view = UIView() let runtime =

    MotionRuntime() How to make things move
  12. // Interaction: Draggable let view = UIView() let runtime =

    MotionRuntime() let draggable = Draggable() How to make things move
  13. // Interaction: Draggable let view = UIView() let runtime =

    MotionRuntime() let draggable = Draggable() runtime.add(draggable, to: view) How to make things move
  14. // Interaction: Draggable let view = UIView() let runtime =

    MotionRuntime() runtime.add(Rotatable(), to: view) How to make things move
  15. // Interaction: Draggable let view = UIView() let runtime =

    MotionRuntime() runtime.add(Scalable(), to: view) How to make things move
  16. Use Core Animation. Generic Interaction types. let spring = Spring<CGFloat>()

    let spring = Spring<CGPoint>() How to make things move
  17. How to make things move Use Core Animation. Generic Interaction

    types. let spring = Spring<CGFloat>() let spring = Spring<CGPoint>() let tween = Tween<CGFloat>() let tween = Tween<CGPoint>()
  18. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() How to make things move
  19. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() How to make things move
  20. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, How to make things move
  21. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, to: runtime.get(view).position) How to make things move
  22. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, to: runtime.get(view).position) How to make things move
  23. Reactive programming view: UIView position: ReactiveProperty<CGPoint> let subscription = position

    .subscribe { value in print(value) } position 50, 50 view Subscription
  24. Reactive programming view: UIView position: ReactiveProperty<CGPoint> let subscription = position

    .subscribe { value in print(value) } Subscription Console 50, 50 position 50, 50 view
  25. Reactive programming view: UIView position: ReactiveProperty<CGPoint> let subscription = position

    .subscribe { value in print(value) } position.value = .init(x: 10, y: 20) Subscription Console 50, 50 10, 20 position 50, 50 view
  26. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, to: runtime.get(view).position) How to make things move
  27. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, to: runtime.get(view).position) spring.destination How to make things move reactive property
  28. // Interaction: Spring let view = UIView() let runtime =

    MotionRuntime() let spring = Spring<CGPoint>() runtime.add(spring, to: runtime.get(view).position) spring.destination.value = CGPoint(x: 75, y: 50) How to make things move
  29. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() How to make things move
  30. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() let tossable = Tossable() How to make things move
  31. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() let tossable = Tossable() runtime.add(tossable, to: view) How to make things move
  32. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() let tossable = Tossable() runtime.add(tossable, to: view) // Under the hood: How to make things move
  33. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() let tossable = Tossable() runtime.add(tossable, to: view) // Under the hood: // runtime.add(spring, to: view.position) // runtime.add(draggable, to: view) How to make things move
  34. // Interaction: Tossable let view = UIView() let runtime =

    MotionRuntime() let tossable = Tossable() runtime.add(tossable, to: view) // Under the hood: // runtime.connect(draggable.finalVelocity, to: spring.initialVelocity) // runtime.add(spring, to: view.position) // runtime.add(draggable, to: view) How to make things move
  35. Interactions Constraints Intro to Material Motion How to make things

    move How to build transitions Closing thoughts
  36. // Customizing interactions - Constraints let draggable = Draggable() runtime.add(draggable,

    to: mochiView, constraints: { return $0.xLocked(to: 100) }) How to make things move
  37. // Customizing interactions - Constraints let draggable = Draggable() runtime.add(draggable,

    to: mochiView, constraints: { return $0.xLocked(to: 100) .rubberBanded(below: -50, above: 50, maxLength: 25) }) How to make things move
  38. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Short summary:
  39. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Short summary: •
  40. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Short summary: • •
  41. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Short summary: • • •
  42. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts
  43. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Using custom transitions Creating a transition
  44. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Using custom transitions Creating a transition
  45. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Using custom transitions Creating a transition
  46. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { } }
  47. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { } }
  48. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { } } • • • •
  49. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y } }
  50. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y } } fore back fore
  51. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y } } fore back back fore back fore
  52. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y runtime.add(TransitionSpring(back: offscreen, fore: onscreen, direction: ctx.direction) to: ctx.fore.positionY) } }
  53. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y runtime.add(TransitionSpring(back: offscreen, fore: onscreen, direction: ctx.direction) to: ctx.fore.positionY) } } back fore
  54. How to build transitions // Building a transition class PushBackTransition:

    Transition { func willBegin(ctx: TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y runtime.add(TransitionSpring(back: offscreen, fore: onscreen, direction: ctx.direction) to: ctx.fore.positionY) runtime.add(TransitionSpring(back: 1, fore: 0.95, direction: ctx.direction), to: ctx.back.scale) } }
  55. // Building a transition class PushBackTransition: Transition { func willBegin(ctx:

    TransitionContext, runtime: MotionRuntime) { let offscreen = ctx.height + ctx.fore.height / 2 let onscreen = ctx.center.y runtime.add(TransitionSpring(back: offscreen, fore: onscreen, direction: ctx.direction) to: ctx.fore.positionY) runtime.add(TransitionSpring(back: 1, fore: 0.95, direction: ctx.direction), to: ctx.back.scale) } } How to build transitions
  56. Summary: Intro to Material Motion How to make things move

    How to build transitions Closing thoughts
  57. Summary: • Intro to Material Motion How to make things

    move How to build transitions Closing thoughts
  58. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts Summary: • • reactive
  59. Intro to Material Motion How to make things move How

    to build transitions Closing thoughts
  60. responsive Intro to Material Motion How to make things move

    How to build transitions Closing thoughts
  61. responsive • • • • • Intro to Material Motion

    How to make things move How to build transitions Closing thoughts
  62. responsive • • • • • github.com/material-motion Intro to Material

    Motion How to make things move How to build transitions Closing thoughts
  63. responsive • • • • • github.com/material-motion discord.gg/ZJyGXza Intro to

    Material Motion How to make things move How to build transitions Closing thoughts
  64. Some quick background on Core Animation (CA) • CA animations

    occur on the render server. Core Animation
  65. Some quick background on Core Animation (CA) • CA animations

    occur on the render server. • The render server is independent from your app’s main thread. Core Animation
  66. Some quick background on Core Animation (CA) • CA animations

    occur on the render server. • The render server is independent from your app’s main thread. This means CA animations aren’t subject to main-thread jank. Core Animation
  67. Core Animation Some quick background on Core Animation (CA) •

    CA animations occur on the render server. • The render server is independent from your app’s main thread. This means CA animations aren’t subject to main-thread jank. Third-party animation libraries like Facebook’s POP operate on the main thread, which is why POP is often used hand-in-hand with AsyncDisplayKit.