SharedTransitionScope.ResizeMode



There are two different modes to resize child layout of sharedBounds during bounds transform: 1) ScaleToBounds and 2) RemeasureToBounds.

ScaleToBounds first measures the child layout with the lookahead constraints, similar to skipToLookaheadSize. Then the child's stable layout will be scaled to fit in the shared bounds.

In contrast, RemeasureToBounds will remeasure and relayout the child layout of sharedBounds with animated fixed constraints based on the size of the bounds transform. The re-measurement is triggered by the bounds size change, which could potentially be every frame.

ScaleToBounds works best for Texts and bespoke layouts that don't respond well to constraints change. RemeasureToBounds works best for background, shared images of different aspect ratios, and other layouts that adjust themselves visually nicely and efficiently to size changes.

Summary

Public companion functions

SharedTransitionScope.ResizeMode
ScaleToBounds(contentScale: ContentScale, alignment: Alignment)

ScaleToBounds as a type of ResizeMode will measure the child layout with lookahead constraints to obtain the size of the stable layout.

Cmn

Public companion properties

SharedTransitionScope.ResizeMode

In contrast to ScaleToBounds, RemeasureToBounds is a ResizeMode that remeasures and relayouts its child whenever bounds change during the bounds transform.

Cmn

Public companion functions

ScaleToBounds

fun ScaleToBounds(
    contentScale: ContentScale = ContentScale.FillWidth,
    alignment: Alignment = Alignment.Center
): SharedTransitionScope.ResizeMode

ScaleToBounds as a type of ResizeMode will measure the child layout with lookahead constraints to obtain the size of the stable layout. This stable layout is the post-animation layout of the child. Then based on the stable size of the child and the animated size of the sharedBounds, the provided contentScale will be used to calculate a scale for both width and height. The resulting effect is that the child layout does not re-layout during the bounds transform, contrary to RemeasureToBounds mode. Instead, it will scale the stable layout based on the animated size of the sharedBounds.

ScaleToBounds works best for sharedBounds when used to animate shared Text.

ContentScale.FillWidth is the default value for contentScale. alignment will be used to calculate the placement of the scaled content. It is Alignment.Center by default.

Public companion properties

RemeasureToBounds

val RemeasureToBoundsSharedTransitionScope.ResizeMode

In contrast to ScaleToBounds, RemeasureToBounds is a ResizeMode that remeasures and relayouts its child whenever bounds change during the bounds transform. More specifically, when the sharedBounds size changes, it creates fixed constraints based on the animated size, and uses the fixed constraints to remeasure the child. Therefore, the child layout of sharedBounds will likely change its layout to fit in the animated constraints.

RemeasureToBounds mode works well for layouts that respond well to constraints change, such as background and Images. It does not work well for layouts with specific size requirements. Such layouts include Text, and bespoke layouts that could result in overlapping children when constrained to too small of a size. In these cases, it's recommended to use ScaleToBounds instead.