Skip to content

Lottie grandchild fix v2 - #2802

Open
MarkYav wants to merge 3 commits into
google:mainfrom
MarkYav:lottie-grandchild-fix-v2
Open

Lottie grandchild fix v2#2802
MarkYav wants to merge 3 commits into
google:mainfrom
MarkYav:lottie-grandchild-fix-v2

Conversation

@MarkYav

@MarkYav MarkYav commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Fix for #2795

WHAT

  • Replaced the simple parentTransforms mapping with a topological traversal algorithm (buildAncestorTransforms) to capture the entire hierarchy of ancestral transforms for each layer.
  • Refactored Layer node parameters to expect and resolve the full topologically sorted ancestorStack: List.
  • Updated ShapeLayer structure so it correctly merges transforms, strictly preserving the top-down cascading render sequence (e.g., [Grandparent, Parent, Self]).
  • Wrapped the heavy hierarchical allocation in a remember(animation.layers) block in LottieAnimation to prevent severe GC churn and UI jank during recompositions.

WHY

  • Previously, Lottie layers completely discarded transforms generated past their immediate parent, causing visual breaks for deeply nested Lottie files. Providing the entire ancestral lineage as a sequential List allows the RemoteCanvas affine matrix to apply each layer's intrinsic rotation, translation, and custom anchors gracefully and truthfully to the Lottie spec.

HOW

Checklist 📋

  • Add explicit visibility modifier and explicit return types for public declarations
  • Run spotless check
  • Run tests
  • Update metalava's signature text files

Replaced the shallow parent mapping with a topological traversal algorithm (buildAncestorTransforms) to accurately capture the entire hierarchy of ancestral transforms for each layer.

Previously, Lottie layers completely discarded transforms generated past their immediate parent, breaking deep Lottie hierarchies. Providing the entire ancestral lineage as a sequential list natively preserves the top-down cascading render sequence, letting the RemoteCanvas apply each layer's intrinsic rotation, translation, and custom anchor points accurately.

Additionally, wrapped the heavy hierarchical list allocations in a remember(animation.layers) block in LottieAnimation to prevent Garbage Collection churn and performance lags during recompositions.
// TODO: Replace passing a transform param in and applying it to the transform stack with
// graphicsLayer transforms in the calling composable, once the ANDROID_NATIVE player supports
// graphicsLayer
// (b/408913726)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this comment, it's not true any more.

private fun populateAncestorTransforms(
layer: com.google.android.horologist.remotecompose.lottie.format.Layer,
currentStack:
List<com.google.android.horologist.remotecompose.lottie.format.GraphicElement.Transform>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports

}
}

composeRule.onNodeWithTag("Box").captureRoboImage(testName("_grandparent"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard from the test to reason about whether it's right or wrong. Can we either describe how to tell if it's working.

or alternatively, is there a way to make the image tell a story. Such as each layer being a some item like a circle with a number, and the transforms make each layer move out of the way, but without the grandparent, you won't see all 3?

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

Successfully merging this pull request may close these issues.

2 participants