Class

SharedTransitionScope.SharedContentState

SharedContentState is designed to allow access of the properties of sharedBounds/sharedElement, such as whether a match of the same key has been found in the SharedTransitionScope, its clipPathInOverlay and parentSharedContentState if there is a parent sharedBounds in the layout tree.

Source set: Common
public class SharedContentState
    internal constructor(
        public val key: Any,
        config: SharedContentConfig = SharedTransitionDefaults.SharedContentConfig,
    )

SharedContentState is designed to allow access of the properties of sharedBounds/sharedElement, such as whether a match of the same key has been found in the SharedTransitionScope, its clipPathInOverlay and parentSharedContentState if there is a parent sharedBounds in the layout tree.

Properties

isMatchFound

Source set: Common
public val isMatchFound: Boolean

Indicates whether a match of the same key has been found. sharedElement or sharedBounds will not have any animation unless a match has been found.

Caveat: isMatchFound is only set to true after a new sharedElement/sharedBounds of the same key has been composed. If the new sharedBounds/sharedElement is declared in subcomposition (e.g. a LazyList) where the composition happens as a part of the measure/layout pass, that's when isMatchFound will become true.

clipPathInOverlay

Source set: Common
public val clipPathInOverlay: Path?

The resolved clip path in overlay based on the OverlayClip defined for the shared content. clipPathInOverlay is set during Draw phase, before children are drawn. This means it is safe to query parentSharedContentState's clipPathInOverlay when the shared content is drawn.

parentSharedContentState

Source set: Common
public val parentSharedContentState: SharedContentState?

Returns the SharedContentState of a parent sharedBounds, if any.

Functions

prepareTransitionWithInitialVelocity

public fun prepareTransitionWithInitialVelocity(initialVelocity: Velocity)

prepareTransitionWithInitialVelocity sets up the initial velocity for the upcoming shared element transition. This function should be called during the gesture handling to allow the system to acquire the animation start time in the next (i.e. earliest) animation frame to ensure a smooth velocity handoff.

The velocity will used for both incoming and outgoing shared content defined with the same key once shared element transition starts. The animationSpec used to animate the momentum will be the same as what is used by the incoming shared element's bounds transform to keep consistent motion. If the incoming shared element uses a duration-based animation, a default spring will be used instead.

Note: This function will have no effect if the shared element is not enabled (i.e. SharedContentConfig.isEnabled is false). This velocity will only apply to the next shared element transition.

Parameters

initialVelocity The velocity from the gesture system (e.g., from onDragEnd).

Last updated: