Skip to content

Lottie grandchild fix v2 - #2802

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

Lottie grandchild fix v2#2802
MarkYav wants to merge 6 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.
}
}

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?

MarkYav and others added 3 commits August 18, 2026 08:54
1. Red Square (Root layer): Drawn in the top-left at [0, 0].
2. Blue Square (Parent layer): Shifts its local child to the top-right at [96, 0].
3. Green Square (Child layer): Shifts its local child down by [0, 96].

Because the Green Square is a child of the blue square, it inherits the [96, 0] translation and applies its own [0, 96] translation. This means if the Lottie engine correctly parses all 3 tiers of the hierarchy, the Green Square correctly lands in the bottom-right corner.

If the bug was still present (where it ignorantly dropped the grandparent's transform), the Green Square would wrongly render in the bottom-left corner.
@github-actions

Copy link
Copy Markdown

Preview Changes

Warning

1 preview(s) failed to render in this PR's render run. The diff below covers only the previews that produced a PNG.

Changed (2 variant(s) across 2 function(s))

LottieGeometryPreview (remotecompose:lottie)

Before After

LottieParentChainPreview (remotecompose:lottie)

Before After

Render Failures (1 variant(s) across 1 function(s))

The render task completed but produced no PNG for these previews. Common causes: Robolectric sandbox crash, composePreviewRender NO-SOURCE, or a runtime exception inside the composable. Check the composePreviewRender-reports artifact attached to this run.

  • WearAppPreview (sample) — src/main/java/com/google/android/horologist/ambient/AmbientAwareActivity.kt
    • sample/com.google.android.horologist.ambient.AmbientAwareActivityKt.WearAppPreview_Devices - Large Round · Devices - Large Round
Unchanged (382 function(s), 564 variant(s))
  • AccountChipPreview
  • AccountChipPreviewNoAvatar
  • ActiveDurationTextCustomSeparatorPreview
  • ActiveDurationTextPreview
  • AlertDialogPreview
  • AlertDialogWithIconPreview
  • AlertDialogWithLongBodyPreview
  • AmbientMediaControlButtonsDisabledPreview
  • AmbientMediaControlButtonsPausedPreview
  • AmbientMediaControlButtonsPlayingPreview
  • AmbientMediaInfoDisplayLoadingPreview
  • AmbientMediaInfoDisplayNothingPlayingPreview
  • AmbientMediaInfoDisplayPreview
  • AmbientMessageDisplayPreview
  • AmbientPlayPauseButtonDisabledPreview
  • AmbientPlayPauseButtonPausedPreview
  • AmbientPlayPauseButtonPlayingPreview
  • AmbientPlayerScreenNothingPlayingPreview
  • AmbientPlayerScreenPausedPreview
  • AmbientPlayerScreenPreview
  • AmbientSeekToNextButtonPreview
  • AmbientSeekToPreviousButtonPreview
  • AnimatedMediaControlButtonsBufferingPreview
  • AnimatedMediaControlButtonsDisabledPreview
  • AnimatedMediaControlButtonsPausedPreview
  • AnimatedMediaControlButtonsPlayingPreview
  • AnimatedPlayPauseButtonPreview
  • AnimatedPlayPauseMorphPreview
  • AnimatedPlayPauseProgressButtonLoadingPreview
  • AnimatedPlayPauseProgressButtonMorphPreview
  • AnimatedPlayPauseProgressButtonPausedPreview
  • AnimatedPlayPauseProgressButtonPlayingPreview
  • AnimatedPlayPauseProgressButtonPreview
  • AnimatedSeekToNextButtonPreview
  • AnimatedSeekToNextButtonPreviewDisabled
  • AnimatedSeekToNextButtonPreviewEnabled
  • AnimatedSeekToPreviousButtonPreview
  • AnimatedSetVolumeButtonPreview
  • AnimatedVolumeButtonMotionPreview
  • ArtworkImageBackgroundPreview
  • AudioOutputButtonPreview
  • AuditMenuScreenPreview
  • AuthErrorScreenPreview
  • AuthMenuScreenPreview
  • BrowseScreenPreview
  • BrowseScreenPreviewEmpty
  • BrowseScreenPreviewFailed
  • BrowseScreenPreviewLoading
  • ButtonPreview
  • ButtonPreviewCustomSize
  • ButtonPreviewDisabled
  • ButtonPreviewLarge
  • ButtonPreviewSmall
  • ButtonPreviewWithIconButtonColors
  • ButtonPreviewWithSecondaryButtonColors
  • CardsAuditPreview
  • CheckYourPhoneScreenPreview
  • CheckYourPhoneScreenPreviewWithMessage
  • ChipIconWithProgressInProgressLargeIconPreview
  • ChipIconWithProgressInProgressMediumIconPreview
  • ChipIconWithProgressInProgressPreview
  • ChipIconWithProgressInProgressSmallIconPreview
  • ChipIconWithProgressPreview
  • ChipIconWithProgressWithIconPreview
  • ChipPreview
  • ChipPreviewDisabled
  • ChipPreviewWithGradientBackgroundChipColors
  • ChipPreviewWithIcon
  • ChipPreviewWithImageBackgroundChipColors
  • ChipPreviewWithLargeIcon
  • ChipPreviewWithSecondaryChipColors
  • ChipPreviewWithSecondaryLabel
  • ChipPreviewWithSecondaryLabelAndIcon
  • ChipPreviewWithSecondaryLabelAndLargeIcon
  • ColorBackgroundPreview
  • CompactChipPreview
  • CompactChipPreviewIconOnly
  • CompactChipPreviewWithIcon
  • ConfirmationLongTitlePreview
  • ConfirmationPreview
  • CreateAccountChipPreview
  • CreateAccountChipPreviewLargeIconSpace
  • CurvedTimeTextAuditPreview
  • DatePickerPreview
  • DatePickerPreviewLargeDeviceSmallFont
  • DatePickerPreviewSmallDeviceWithLargeFontBold
  • DefaultPreview
  • DeviceChipPreview
  • EntityButtonPreviewDisabled
  • EntityButtonPreviewEnabled
  • EntityScreenPreview
  • EntityScreenPreviewFailedState
  • EntityScreenPreviewLoaded
  • EntityScreenPreviewLoadedState
  • EntityScreenPreviewLoading
  • EntityScreenPreviewLoadingState
  • FailedResponseChipPreview
  • FillMaxRectanglePreview
  • GoogleSignInPromptSampleScreenPreview
  • GuestModeButtonPreview
  • GuestModeChipPreview
  • IconPreview
  • IconPreviewMirrored
  • InfoScreenPreview
  • InstallAppBottomSheetContentPreview
  • InstallAppBottomSheetContentPreviewNoIcon
  • InstallAppBottomSheetLandscapeContentPreview
  • InstallAppBottomSheetLandscapeContentPreviewNoIcon
  • InstallAppCustomPromptDemoScreenPreview
  • InstallAppCustomPromptDemoScreenPreviewWithPrompt
  • InstallAppPromptDemoScreenPreview
  • InstallTileBottomSheetContentPreview
  • InstallTileBottomSheetContentPreviewNoIcon
  • InstallTileBottomSheetLandscapeContentPreview
  • InstallTileBottomSheetLandscapeContentPreviewNoIcon
  • InstallTileCustomPromptDemoScreenPreview
  • InstallTileCustomPromptDemoScreenPreviewWithPrompt
  • InstallTilePromptDemoScreenPreview
  • LoadingMediaDisplayPreview
  • LottieGeometryAnimatedPreview
  • LottieM3PlayPauseAnimatedPreview
  • LottieM3PlayPausePreview
  • LottieNextAnimatedPreview
  • LottieNextPreview
  • LottiePlayPauseAnimatedPreview
  • LottiePlayPausePauseStatePreview
  • LottiePlayPausePreview
  • LottiePositionAnimatedLivePreview
  • LottiePositionAnimatedPreview
  • LottiePositionStaticPreview
  • LottieTintGeometryAnimatedPreview
  • LottieTintGeometryPreview
  • MainPreview
  • MainScreenPreview
  • MarqueeTextConstantScrollingPreview
  • MarqueeTextConstantWithIconScrollingPreview
  • MarqueeTextMediaDisplayPreview
  • MarqueeTextShortTextCenterPreview
  • MarqueeTextShortTextRightPreview
  • MarqueeTextShortTextRtlPreview
  • MarqueeTextStyledPreview
  • MarqueeTextTypicalPreview
  • MediaArtworkPreview
  • MediaButtonPreview
  • MediaChipPreview
  • MediaChipPreviewNoArtwork
  • MediaChipPreviewNoTitle
  • MediaChipPreviewVeryLongTitle
  • MediaControlButtonsDisabledPreview
  • MediaControlButtonsPausedPreview
  • MediaControlButtonsPlayingPreview
  • MediaControlButtonsPreview
  • MediaControlButtonsPreviewNoProgress
  • MediaDetailsButtonPreview
  • MediaTitleIconPreview
  • MenuScreenPreview
  • MessageMediaDisplayPreview
  • MetricDisplayPreview
  • MetricDisplayPreviewBottomRightText
  • MetricDisplayPreviewTextOnly
  • MetricDisplayPreviewTopRightText
  • MetricsScreenPreviewFourMetrics
  • MetricsScreenPreviewOneMetric
  • MetricsScreenPreviewThreeMetrics
  • MetricsScreenPreviewTwoMetrics
  • NodeCardPreview
  • NodeDetailsScreenPreview
  • NodesActionDialogPreview
  • NodesActionFailureDialogPreview
  • NodesActionSucceededDialogPreview
  • NodesActionsScreenPreviewApiNotAvailable
  • NodesActionsScreenPreviewEmptyNodes
  • NodesActionsScreenPreviewLoaded
  • NodesListenerScreenPreview
  • NodesListenerScreenPreviewApiNotAvailable
  • NodesListenerScreenPreviewEmptyNodes
  • NodesListenerScreenPreviewLoaded
  • NodesScreenPreview
  • NodesScreenPreviewApiNotAvailable
  • NodesScreenPreviewEmptyNodes
  • NothingPlayingDisplayPreview
  • OtherOptionsChipPreview
  • OutlinedChipPreview
  • OutlinedChipPreviewDisabled
  • OutlinedChipPreviewWithIcon
  • OutlinedChipPreviewWithLargeIcon
  • OutlinedChipPreviewWithSecondaryLabel
  • OutlinedChipPreviewWithSecondaryLabelAndIcon
  • OutlinedChipPreviewWithSecondaryLabelAndLargeIcon
  • OutlinedCompactChipPreview
  • OutlinedCompactChipPreviewIconOnly
  • OutlinedCompactChipPreviewWithIcon
  • PageIndicatorLeft5PlusAuditPreview
  • PageIndicatorRight5PlusAuditPreview
  • PagerScreenPreview
  • PagingItemCardPreviewWithDelayedContent
  • PagingItemCardPreviewWithInitialContent
  • PauseButtonPreview
  • PlaceholderChipPreview
  • PlaceholderChipPreviewWithSecondaryColors
  • PlayButtonPreview
  • PlayPauseButtonPreview
  • PlayPauseProgressButtonLoadingPreview
  • PlayPauseProgressButtonPausedPreview
  • PlayPauseProgressButtonPlayingPreview
  • PlayPauseProgressButtonPreview0
  • PlayPauseProgressButtonPreview100
  • PlayPauseProgressButtonPreview25
  • PlayPauseProgressButtonPreview75
  • PlayPauseProgressButtonPreviewOnWhite
  • PlayerLibraryPagerScreenPreview
  • PlayerScreenCustomBackgroundPreview
  • PlayerScreenLongTextPreview
  • PlayerScreenNothingPlayingPreview
  • PlayerScreenPausedPreview
  • PlayerScreenPreview
  • PlayerScreenPreviewCustomBackground
  • PlayerScreenPreviewCustomMediaDisplay
  • PlayerScreenPreviewDevices
  • PlayerScreenPreviewNotingPlayingDisplay
  • PlayerScreenPreviewUamp
  • PlayerScreenThemePreview
  • PlaylistDownloadBrowseScreenPreview
  • PlaylistDownloadBrowseScreenPreviewLoading
  • PlaylistDownloadBrowseScreenPreviewNoDownloads
  • PlaylistDownloadBrowseScreenPreviewUampTheme
  • PlaylistDownloadScreenPreview
  • PlaylistDownloadScreenPreviewFailed
  • PlaylistDownloadScreenPreviewLoadedFullyDownloaded
  • PlaylistDownloadScreenPreviewLoadedNoneDownloaded
  • PlaylistDownloadScreenPreviewLoadedNoneDownloadedDownloading
  • PlaylistDownloadScreenPreviewLoadedPartiallyDownloaded
  • PlaylistDownloadScreenPreviewLoadedPartiallyDownloadedDownloadingUnknownSize
  • PlaylistDownloadScreenPreviewLoadedPartiallyDownloadedDownloadingWaiting
  • PlaylistDownloadScreenPreviewLoading
  • PlaylistStreamingScreenPreview
  • PlaylistsScreenLongPreview
  • PlaylistsScreenPreview
  • PlaylistsScreenPreviewCustomLayout
  • PlaylistsScreenPreviewFailed
  • PlaylistsScreenPreviewLoaded
  • PlaylistsScreenPreviewLoading
  • PodcastControlButtonsPausedPreview
  • PodcastControlButtonsPlayingPreview
  • PodcastControlButtonsPreview
  • PodcastControlButtonsPreviewNoProgress
  • PodcastControlButtonsPreviewUnknown
  • PodcastControlDisabledLightBackground
  • Preview
  • PreviewHighCornerRadius
  • PreviewProgressAnimation
  • PreviewSquare
  • PreviewSquareWithBrushAndColorsCombined
  • PreviewSquareWithBrushColors
  • PromptScreenErrorPreview
  • PromptScreenMultiTurnPreview
  • PromptScreenStreamingPreview
  • PromptScreenSuccessPreview
  • RadialBackgroundPreview
  • ReEngageBottomSheetContentPreview
  • ReEngageBottomSheetContentPreviewNoIcon
  • ReEngageBottomSheetLandscapeContentPreview
  • ReEngageBottomSheetLandscapeContentPreviewNoIcon
  • ReEngageCustomPromptDemoScreenPreview
  • ReEngagePromptDemoScreenPreview
  • ResponseInProgressCardPreview
  • SamplePromptScreenPreviewEmpty
  • SamplePromptScreenPreviewMany
  • SamplePromptScreenPreviewMarkdown
  • SamplePromptScreenPreviewQuestion
  • SampleTilePreview
  • ScratchPreview
  • ScrollAwayScreenPreview
  • SecondaryTitlePreview
  • SecondaryTitlePreviewWithIcon
  • SecondaryTitlePreviewWithIconAndLongText
  • SecondaryTitlePreviewWithLongText
  • SectionedListExpandableScreenPreview
  • SectionedListPreviewEmptySection
  • SectionedListPreviewFailedSection
  • SectionedListPreviewLoadedSection
  • SectionedListPreviewLoadingSection
  • SectionedListStatefulScreenPreview
  • SectionedListStatelessScreenPreview
  • SeekButtonsGalleryPreview
  • SeekButtonsPreview
  • SeekToNextButtonPreview
  • SeekToPreviousButtonPreview
  • SegmentedProgressIndicatorBrushColorCombinedPreview
  • SegmentedProgressIndicatorBrushPreview
  • SegmentedProgressIndicatorRoundPreview
  • SegmentedProgressIndicatorSquarePreview
  • SelectAccountScreenManyAccountsPreview
  • SelectAccountScreenOneLineAccountsPreview
  • SelectAccountScreenPreview
  • SelectAccountScreenPreviewNoAvatar
  • SetAudioOutputButtonPreview
  • SetAudioOutputButtonPreviewMaxVolume
  • SetAudioOutputButtonPreviewMinVolume
  • SetAudioOutputButtonPreviewNoOutput
  • SetVolumeButtonPreview
  • SetVolumeButtonPreviewMaxVolume
  • SetVolumeButtonPreviewMinVolume
  • SettingsButtonsDisabledPreview
  • SettingsButtonsPreview
  • SettingsButtonsWithBrandIconPreview
  • SettingsScreenPreview
  • ShowPlaylistButtonPreview
  • ShowPlaylistChipPreview
  • ShowPlaylistChipPreviewNoArtwork
  • ShowPlaylistChipPreviewNoName
  • ShowPlaylistChipPreviewVeryLongName
  • ShuffleToggleButtonPreview
  • SignInBottomSheetContentPreview
  • SignInBottomSheetContentPreviewNoIcon
  • SignInBottomSheetLandscapeContentPreview
  • SignInBottomSheetLandscapeContentPreviewNoIcon
  • SignInButtonPreview
  • SignInChipPreview
  • SignInCustomPromptDemoScreenPreview
  • SignInCustomPromptDemoScreenPreviewWithPrompt
  • SignInPlaceholderScreenPreview
  • SignInPromptDemoScreenPreview
  • SignInPromptScreenPreviewCustomLoading
  • SignInPromptScreenPreviewLoading
  • SignInPromptScreenPreviewSignedOut
  • SignedInConfirmationDialogMinimalPreview
  • SignedInConfirmationDialogPreview
  • SignedInConfirmationDialogTruncationPreview
  • SplitToggleChipCheckboxPreview
  • SplitToggleChipPreviewDisabled
  • SplitToggleChipRadioPreview
  • SplitToggleChipSwitchPreview
  • SplitToggleChipUncheckedAndDisabledPreview
  • SplitToggleChipUncheckedPreview
  • SplitToggleChipWithSecondaryLabel
  • Standard
  • StepperFloatPreview
  • StepperPreview
  • TextMediaDisplayLongTextPreview
  • TextMediaDisplayPreview
  • TextMediaDisplayPreviewLongText
  • TextPromptDisplayPreview
  • TextResponseCardPreview
  • TimePicker12hPreview
  • TimePicker12hPreviewLargeDeviceSmallFont
  • TimePicker12hPreviewSmallDeviceWithLargeFontBold
  • TimePickerPreview
  • TimePickerPreviewLargeDeviceSmallFont
  • TimePickerPreviewSmallDeviceWithLargeFontBold
  • TitlePreview
  • TitlePreviewWithLongText
  • ToggleButtonPreview
  • ToggleButtonPreviewDisabled
  • ToggleButtonPreviewIconOnly
  • ToggleButtonPreviewIconOnlyNotChecked
  • ToggleButtonPreviewNotChecked
  • ToggleButtonPreviewNotCheckedDisabled
  • ToggleButtonPreviewSmall
  • ToggleButtonPreviewSmallNotChecked
  • ToggleButtonPreviewText
  • ToggleButtonPreviewTextNotChecked
  • ToggleChipCheckboxPreview
  • ToggleChipPreviewDisabled
  • ToggleChipPreviewWithIcon
  • ToggleChipPreviewWithSecondaryLabelAndIcon
  • ToggleChipRadioPreview
  • ToggleChipSwitchPreview
  • ToggleChipUncheckedAndDisabledPreview
  • ToggleChipUncheckedPreview
  • ToggleChipWithSecondaryLabel
  • TrackMediaDisplayPreview
  • TrackMediaDisplayPreviewLongText
  • TrackingScreenPreview
  • VerticalPagerIndicatorPreview
  • VolumeScreenLocalePreview
  • VolumeScreenLongLabelPreview
  • VolumeScreenPreview
  • VolumeScreenTheme
  • VolumeScreenWithLabel
  • WearAppPreview
  • WearableOssLicensesActivity

}
}

private fun buildAncestorTransforms(layers: List<Layer>): Map<Int, List<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.

After we land this, I might see if we can implement this as nested transforms, which is closer to the Compose way.

But not blocking for now.

@yschimke yschimke left a comment

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.

After fixing the screenshot

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