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

Shape Shifting: Creating delightful icon animations

Or Bar
July 13, 2017

Shape Shifting: Creating delightful icon animations

Or Bar

July 13, 2017
Tweet

More Decks by Or Bar

Other Decks in Programming

Transcript

  1. History • Menu to Back animation - ActionBarDrawerToggle • Timely

    • Number Tweening • https://sriramramani.wordpress.com/2013/10/14/number-tweening/
  2. More than just an icon • An icon is more

    than just the sum of its parts • Can indicate its purpose • Can convey information to your users
  3. SVG • Scalable Vector Graphics • An image format that

    describes shapes rather then pixels. • xml based • Version 1.1
  4. SVG <?xml version="1.0" encoding="UTF-8"?> <svg width="48px" height="48px" viewBox="0 0 48

    48" version="1.1" xmlns="http:// www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch --> <title>btn_bold</title> <desc>Created with Sketch.</desc> <defs></defs> <g id="_Assets" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="btn_bold" fill-rule="nonzero" fill="#8F8F8F"> <path d=“M30.156,27.644 … Z” id="B"></path> </g> </g> </svg>
  5. Coordinate System • Width(x) and Height(y) - px, cm, mm,

    pt • Supports Transformations • viewBox - <min-x> <min-y> <width> <height>
  6. Path • Paths represent the outline of a shape which

    can be filled, stroked, or used as a clipping path • d - Path data attribute • e.g. "M 100, 100 L 300, 100 L 200, 300 z” • fill - the color to fill the final shape • stroke - the path color • fill-rule - how to fill the resulting shape
  7. Path Data - lineto • Draws new line from current

    point to new point • L (x, y) • Variants • H (x) • V (y) M 10, 10 L 38,10 v 10 M 10, 10 L 38,10 v 10 M 10, 10 L 38,10 v 10
  8. Path Data - curveto • Draws a cubic Bézier curve

    • C (x1 y1 x2 y2 x y) • Variants • S, Q, T, and A M 10, 10 L 38,10 v 10 C 38, 38 10, 38 10, 20 M 10, 10 L 38,10 v 10 C 38, 38 10, 38 10, 20 M 10, 10 L 38,10 v 10 C 38, 38 10, 38 10, 20 M 10, 10 L 38,10 v 10 C 38, 38 10, 38 10, 20
  9. Path Data - closepath • Draws a straight line to

    the current subpath’s starting point • Z M 10, 10 L 38,10 v 10 C 38, 38 10, 38, 10, 20 Z M 10, 10 L 38,10 v 10 C 38, 38 10, 38, 10, 20 Z
  10. Path - Stroke • stroke - color of the path

    • stroke=“red” • stroke-width - the thickness of the path • stroke-width="2"
  11. Path - Fill • fill - color of the inner

    area of the path • fill=“blue” • fill-rule - The rule to use to fill the shape
  12. VectorDrawable • Android’s version of svg • Small subset of

    the entire svg spec • Different syntax Me Too
  13. Coordinate System • viewportWidth and viewportHeight • width and height

    android:width="48dp" android:height="48dp" android:viewportHeight=“24" android:viewportWidth="24"
  14. VectorDrawable <vector android:width=“24dp” android:height=“24dp” android:viewportHeight=“24.0” android:viewportWidth=“24.0”> <path android:name=“circle” android:fillColor=“#33d4db” android:pathData=“M12,12m-10,0a10,10

    0,1 1,20 0a10,10 0,1 1,-20 0” /> <path android:name=“tick” android:pathData=“M6,11 l3.5,4 l8,-7” android:strokeColor=“#ff3b80” android:strokeWidth=“#1” /> </vector>
  15. VectorDrawable <vector android:width=“24dp” android:height=“24dp” android:viewportHeight=“24.0” android:viewportWidth=“24.0”> <path android:name=“circle” android:fillColor=“#33d4db” android:pathData=“M12,12m-10,0a10,10

    0,1 1,20 0a10,10 0,1 1,-20 0” /> <path android:name=“tick” android:pathData=“M6,11 l3.5,4 l8,-7” android:strokeColor=“#ff3b80” android:strokeWidth=“#1” /> </vector>
  16. VectorDrawable <vector android:width=“24dp” android:height=“24dp” android:viewportHeight=“24.0” android:viewportWidth=“24.0”> <path android:name=“circle” android:fillColor=“#33d4db” android:pathData=“M12,12m-10,0a10,10

    0,1 1,20 0a10,10 0,1 1,-20 0” /> <path android:name=“tick” android:pathData=“M6,11 l3.5,4 l8,-7” android:strokeColor=“#ff3b80” android:strokeWidth=“#1” /> </vector>
  17. Easy Solution • Use Support library 25.4.0 or newer •

    Supports evenodd rule • Supports AnimatedVectorDrawables
  18. AnimatedVectorDrawable • AnimatedVectorDrawables are the glue that connects VectorDrawables with

    ObjectAnimators • Allow you to independently animate paths or group of paths
  19. Path Morphing Paths have to be compatible 1. Path A

    and path B must have the same number of drawing commands. 2. The nth drawing command in path A must have the same type as the nth drawing command in path B, for all n. 3. The nth drawing command in path A must have the same number of parameter as the nth drawing command in path B, for all n.
  20. Path Morphing Minus: M 5,11 L 19,11 L 19,13 L

    5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  21. Path Morphing Minus: M 5,11 L 19,11 L 19,13 L

    5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  22. Path Morphing Minus: M 5,11 L 19,11 L 19,13 L

    5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  23. Path Morphing Minus: M 5,11 L 19,11 L 19,13 L

    5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  24. Path Morphing Minus: M 5,11 L 19,11 L 19,13 L

    5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  25. Path Morphing Minus: M 5,11 L 11,11 L 11,11 L

    13,11 L 13,11 L 19,11 L 19,13 L 13,13 L 13,13 L 11,13 L 11,13 L 5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  26. Path Morphing Minus: M 5,11 L 11,11 L 11,11 L

    13,11 L 13,11 L 19,11 L 19,13 L 13,13 L 13,13 L 11,13 L 11,13 L 5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  27. Path Morphing Minus: M 5,11 L 11,11 L 11,11 L

    13,11 L 13,11 L 19,11 L 19,13 L 13,13 L 13,13 L 11,13 L 11,13 L 5,13 Z Plus: M 5,11 L 11,11 L 11,5 L 13,5 L 13,11 L 19,11 L 19,13 L 13,13 L 13,19 L 11,19 L 11,13 L 5,13 Z
  28. Path Clipping <Clip-path> only operates on it’s siblings. <vector> <path

    android:name=“strike_through"/> <group> <clip-path android:name=“eye_mask” /> <path android:name=“eye” /> </group> </vector>
  29. Resources • ShapeShifter • https://shapeshifter.design • https://github.com/alexjlockwood/adp-delightful- details • Number

    tweening • https://sriramramani.wordpress.com/2013/10/14/ number-tweening/ • Bezier Curves • http://y2u.be/zIXoQNvcNd8