AnimatedContent
A container that animates between the contents of its states. When targetState changes, the new content animates in, the old content animates out, and the container's size animates between them.
Both contents are on screen during the transition, placed by contentAlignment. The old content is removed when its exit finishes, or with AnimatedContentTransitionScope.KeepUntilTransitionsFinished when the whole transition finishes.
AnimatedContent(targetState = page) { shown ->
when (shown) {
Page.Summary -> Summary()
Page.Details -> Details()
}
}The content lambda must show the state it is passed, never a state read elsewhere: the container composes it once per state on screen, and the old content must keep showing its state while it animates out.
This overload works under any parent, including a panel with a standard Swing layout manager and a scroll pane. The container runs the size animation over its own contents and reports the animated size as its preferred size. A parent that assigns fixed bounds, such as a border layout's center or a filling grid-bag cell, shows no size change; the contents' enter and exit still run. Inside a Box, Row, Column or other Foundation layout, the scoped overload applies instead, and the parent lays the container out through the size animation.
Content is clipped to the container by default; set SizeTransform.clip to false to let it extend past the animated size under a Foundation parent. A stock Swing ancestor still clips at its own bounds. Mouse input follows the content's scale. The size animation targets each content's preferred size, which content whose height depends on its width, such as a wrapping text area or an HTML label, reports without knowing its final width.
Text loses LCD subpixel antialiasing while a fade runs: a fade paints through a translucent buffer, and the JDK renders subpixel text only onto an opaque surface. A heavyweight child paints outside the lightweight paint path, so it stays at full opacity and unscaled during the transition.
Focus leaves content when its exit begins, so Tab never moves focus into exiting content.
Parameters
the state whose content the container settles on.
the SwingModifier applied to the container.
how the target content enters, how the old content exits, and how the container's size animates; a short fade and scale in over a shorter fade out by default. See AnimatedContentTransitionScope.
where each content sits inside the container.
names the transition in a tool that inspects a composition. It is read once, when the transition is created.
states with equal keys share one composition and component, so a change between them animates nothing. The state itself by default.
the composable content of one state of the container; see AnimatedContentScope.
A container inside a Foundation layout that animates between the contents of its states.
The parent lays the container out at the animated size. SizeTransform.clip controls whether content extends past that size. Foundation parents carry size-animation paint overflow, while stock Swing ancestors clip at their own bounds. Its intrinsic size is the largest content on screen, which is the target content's size once the transition ends.
Otherwise behaves as the unscoped overload.
Parameters
the state whose content the container settles on.
the SwingModifier applied to the container.
how the target content enters, how the old content exits, and how the container's size animates; a short fade and scale in over a shorter fade out by default. See AnimatedContentTransitionScope.
where each content sits inside the container.
names the transition in a tool that inspects a composition.
what makes two states one content; the state itself by default.
the composable content of one state of the container; see AnimatedContentScope.
A container that animates between the contents of this transition's states. Containers built on one transition animate together.
val transition = updateTransition(page)
transition.AnimatedContent { Body(it) }
transition.AnimatedContent { Footer(it) }On a deferred transition, which announces its next state before animating to it, the container composes the announced content at EnterExitState.PreEnter over the content on screen, so it is measured before the enter starts. The container's size does not change during the deferred phase. If the phase ends without reaching the announced state, that content is removed.
Otherwise behaves as the overload taking a target state, including the size animation under any parent.
Parameters
the SwingModifier applied to the container.
how the target content enters, how the old content exits, and how the container's size animates; a short fade and scale in over a shorter fade out by default. See AnimatedContentTransitionScope.
where each content sits inside the container.
what makes two states one content; the state itself by default.
the composable content of one state of the container; see AnimatedContentScope.