You can modify animation properties at runtime (e.g., for theming or responding to events) using addValueCallback. To target a property, you need three components:
- KeyPath: A list of strings representing the After Effects hierarchy.
- Use
* (Wildcard) to match any single content name in that position. - Use
** (Globstar) to match zero or more layers.
- LottieProperty: An enumeration of the property to change (e.g.,
LottieProperty.COLOR). - LottieValueCallback: A callback that provides frame and progress data to determine the new value.
KeyPath Resolution: If you are unsure of your animation's structure, use resolveKeyPath(KeyPath("**")) on a LottieAnimationView or LottieDrawable to discover the hierarchy. Use the returned resolved KeyPaths for callbacks to avoid expensive tree walks during animation.
// Example: Change a specific fill color based on animation progress
animationView.addValueCallback(
KeyPath("Shape Layer", "Rectangle", "Fill"),
LottieProperty.COLOR,
{ if (it.overallProgress < 0.5) Color.GREEN else Color.RED }
)