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

Customize your Lottie animations

Tiphaine
December 18, 2024

Customize your Lottie animations

Mobile Dev Japan #5 - 18/12/2024
https://mobiledev-japan.connpass.com/event/338503/

Animation GIFs are not moving on PDF format.
Feel free to have a look at the original slides here:
https://docs.google.com/presentation/d/1mYO9NCVbVuIU71eSinVefgUpTO2kzAHdceyBQgZ32BM/edit?usp=sharing

Tiphaine

December 18, 2024
Tweet

More Decks by Tiphaine

Other Decks in Technology

Transcript

  1. Hello! I am Tiphaine ◆ Android dev at DeNA (Pococha)

    ◆ DroidKaigi staff, Mobile Dev Japan co-org 2
  2. Lottie 4 Open-source library for rendering animations on Android, iOS,

    React Native, Web and Windows airbnb.io/lottie
  3. LottieFiles 5 lottiefiles.com Where you can find all related resources:

    other Lottie products, integration tools/plugins, animation assets, tutorials, etc.
  4. Why it’s nice 6 ◆ Lightweight, scalable with larger screens

    ◆ Same file can be used for several platforms ◆ Good balance between customization and ease of implementation
  5. What can you customize? 9 ◆ Basic: iteration/loop, speed, progression

    ◆ Dynamically: colors, stroke width, opacity, font, text size, text, image...
  6. Dynamic Properties 10 Use to update the animation at runtime

    with: ◆ A LottieProperty ◆ A KeyPath Doc: Dynamic Properties
  7. LottieProperty 11 ◆ The animation property you want to change

    ◆ Choose from a list of static constants with pre-defined return types Doc: Animatable Properties list, LottieProperty.java
  8. KeyPath 12 ◆ The path to the node (layer object

    in a JSON) that has the property you target ◆ A list of Strings used to find that target node
  9. 14

  10. 15 Use the values associated with “nm” keys in each

    node you traverse until the target node
  11. 16 Find more about what each JSON key means: Lottie系列二:高级属性

    **Chinese only, sorry 😇 (but Google translate is your friend)
  12. 19 Doc: Animatable Properties list, LottieProperty.java Step 1: choose the

    appropriate LottieProperty LottieProperty.COLOR
  13. 20 // Returns a list of all the nodes (Layer

    objects) LottieAnimationView.resolveKeyPath(KeyPath("**")) Step 2: get the KeyPath of the target node Use this helper method to discover the structure of the JSON file
  14. 21 ◆ Can’t access it through Compose 🥲 ◆ Need

    to temporarily wrap the animation in an AndroidView (just to print the result) Ref: lottie-android issue #2080 But...
  15. 22 val context = LocalContext.current val customView = remember {

    LottieAnimationView(context) } AndroidView({ customView }) { view -> with(view) { setAnimation(R.raw.thanks) // Print the result of this view.resolveKeyPath(KeyPath("**")) } }
  16. 24

  17. 25

  18. 26

  19. 27 // Get all the nodes under “Heart Filled Outlines”

    KeyPath("Love icon", "Heart Filled Outlines", "**") Ref: KeyPath (doc), Dynamic Lottie Animations on Android
  20. 28 Step 3: use the LottieProperty and the KeyPath to

    build a rememberLottieDynamicProperty
  21. 31 LottieAnimation( composition = composition, iterations = LottieConstants.IterateForever, dynamicProperties =

    dynamicProperties, ) Step 5: pass the DynamicProperties to LottieAnimation as an argument
  22. 32 🎉 ✅ Filled heart color is green ✅ Text

    and outlined heart colors did not change