Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve the value of a property? #29

Open
stevekirby opened this issue Sep 12, 2021 · 3 comments
Open

How to retrieve the value of a property? #29

stevekirby opened this issue Sep 12, 2021 · 3 comments

Comments

@stevekirby
Copy link

I'm having no trouble using getKeyPath() and addValueCallback() but I cannot figure out how to simply retrieve the value of a property, eg as an array. How can I determine the Position property of a layer as an array of [x,y,z] values? Better still, where is the documentation that explains how to do this! I've been googling for over an hour for something that seemingly ought to be so simple.

@Inventsable
Copy link

Inventsable commented Sep 12, 2021

Hi Steve. There is no documentation for Lottie-API unfortunately, only what's on the README and the samples:

// Importing lottie-web, lottie API and our JSON:
import * as lottie from "lottie-web"
require("lottie_api.js");
const ANIM_FILE = require("data.json")

// First we load our JSON into Lottie:
const ANIM_DATA = lottie.loadAnimation({
  animType: "svg",
  loop: true,
  prerender: true,
  autoplay: true,
  container: document.getElementById("container"),
  animationData: ANIM_DATA
});

// Then create the API object with our constructed data above:
const API = lottie_api.createAnimationApi(ANIM_DATA) // lottie_api is a global object

// We can retrieve the current X/Y via addValueCallback's second parameter
API.addValueCallback(
  // But we need to feed a reference via the first parameter before this, targeting Layer 1's Transform > Position propGroup:
  API.getKeyPath(`Layer 1,Transform,Position`),
  (currentValue) => {
    // The parameter value here is an Array value of the position. This is only the position at the point of the callback though, not realtime as the animation is playing.

    // If we want to set these to be reactive (but not for getting unfortunately, only setting):
    return [someDynamicX, someDynamicY]
  }
)

@Inventsable
Copy link

#13

@stevekirby
Copy link
Author

Thanks Tom. Through digging into examples I have managed to figure out this which seems to be working:

        var posKeyPath = animationAPI.getKeyPath('Target Layer,Transform,Position');
        var posVal = posKeyPath.getPropertyAtIndex(0).getValue();

Though I have not tested it thoroughly yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants