Fireship · @fireship

Swipe, Tap, Pinch - HammerJS + Angular Animations

Uploaded December 29, 2017 · Length 9:14

Swipe, Tap, Pinch - HammerJS + Angular Animations

Summary

how to add touch events and animations to angular progressive web apps using hammerjs and angular animations

  • angular animations
  • hammerjs
  • touch events
  • progressive web apps
  • angular progressive web apps
  • mobile animations
  • angular mobile development

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    in case you haven't heard the good news

  2. 0:01

    both Microsoft edge and WebKit Safari

  3. 0:03

    are now supporting service workers in

  4. 0:05

    their preview releases this is a huge

  5. 0:07

    leap forward and sets up 2018 to be the

  6. 0:10

    year of progressive web apps with that

  7. 0:12

    being said what I want to show you today

  8. 0:13

    is how to handle touch events that only

  9. 0:15

    happen on mobile devices then use

  10. 0:17

    angular to create animations in response

  11. 0:19

    to these events as you can see here we

  12. 0:21

    run a different animation on this

  13. 0:22

    material card every time the user swipes

  14. 0:25

    in a different direction if you're new

  15. 0:27

    here make sure to subscribe and I

  16. 0:28

    recommend that you follow along with the

  17. 0:29

    source code at angular firebase comm and

  18. 0:32

    while you're at it

  19. 0:33

    I also recommend checking out Paul

  20. 0:34

    Holidays YouTube channel and all the

  21. 0:36

    awesome angular content he's creating

  22. 0:38

    over there I'm going to kick this

  23. 0:40

    episode off by building a brand new

  24. 0:41

    angular app then we have a couple of

  25. 0:43

    dependencies to add the first one being

  26. 0:45

    hammer J S which is used to add support

  27. 0:48

    for mobile touch events to your

  28. 0:49

    progressive web app including rotate

  29. 0:51

    pinch press pan tap and swipe then you

  30. 0:54

    can install it in your app by running

  31. 0:55

    NPM install hammer J s Flags save then

  32. 0:59

    once installed we're going to go into

  33. 1:01

    the main TS file and make sure to import

  34. 1:03

    hammer J s there that'll make the events

  35. 1:05

    globally available throughout your app

  36. 1:07

    in this demo I'm using angular material

  37. 1:09

    but that part is completely optional you

  38. 1:11

    can follow the install instructions on

  39. 1:13

    the official repo the important part is

  40. 1:15

    that you install angular animations

  41. 1:17

    which is included in the angular mono

  42. 1:19

    repo so you can just install it with NPM

  43. 1:21

    and then make sure to include it inside

  44. 1:24

    of your app module so you should have

  45. 1:26

    browser animations module inside of the

  46. 1:28

    imports array we're going to be modeling

  47. 1:31

    our animations after the animate CSS

  48. 1:33

    library which is one of the most popular

  49. 1:35

    libraries on github the library itself

  50. 1:38

    is just a collection of CSS keyframe

  51. 1:41

    animations so all we have to do is port

  52. 1:43

    those over to angular so we can use it

  53. 1:45

    with angular's browser animations module

  54. 1:47

    we don't actually need to install this

  55. 1:49

    package in our angular project instead

  56. 1:51

    we're just going to copy and paste the

  57. 1:53

    CSS keyframes over to the angular

  58. 1:55

    animations keyframes the end result is

  59. 1:58

    that we'll be able to trigger animations

  60. 1:59

    natively in angular this will give us