AnimatedVisibility
A container that animates content in as visible becomes true and out as it becomes false.
The content is removed from the Swing tree when the exit finishes, so a hidden container takes no space. A change to visible during a transition continues from the current values instead of restarting.
AnimatedVisibility(visible = showing) {
Label(text = "Everything about it")
}This overload works under any parent, including a panel with a standard Swing layout manager and a scroll pane. The container runs the size change and the slide over its content and fades the content as one image, so a slide is clipped at the container's bounds. Inside a Box, Row, Column or other Foundation layout, the scoped overload applies instead, and a slide moves the container within its parent.
A size transition reports the animated size as the container's 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. Set clip = false on expandIn or shrinkOut to let content extend past the animated size under a Foundation parent. A stock Swing ancestor still clips at its own bounds.
Container scaling requires a Foundation layout parent; use the overload scoped to a ConstrainedScope for scale transitions. Content whose height depends on its width reports a preferred size the animation cannot match.
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.
When the exit starts, the content leaves focus traversal, and a focused component inside it transfers focus.
Only this container decides whether the content is in the tree. A visible(false) on the content itself still hides it, independently of the transition.
Parameters
whether the content is shown.
the SwingModifier applied to the container.
how the content appears; a fade in together with an expansion from nothing by default.
how the content disappears; a shrink to nothing together with a fade out by default.
names the transition in a tool that inspects a composition. It is read once, when the transition is created.
the composable content of the container; see AnimatedVisibilityScope.
A container inside a Foundation layout that animates content in and out as visible changes.
The parent lays the container out through the transition: the parent arranges the animated size, a slide moves the container within the parent, and the fade and scale are the layer the parent places it with. expandIn and shrinkOut clip to their animated size by default; set their clip parameter to false to let content extend beyond it. Foundation parents map mouse input through scaled placement layers and carry size-animation paint overflow. A background on modifier paints outside the layer, so it is not faded.
Parameters
whether the content is shown.
the SwingModifier applied to the container.
how the content appears; a fade in together with an expansion from nothing by default.
how the content disappears; a shrink to nothing together with a fade out by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
A container that animates content in and out inside a Row, expanding and shrinking horizontally only, so the row's height does not change.
Otherwise behaves as the ConstrainedScope overload.
Parameters
whether the content is shown.
the SwingModifier applied to the container.
how the content appears; a fade in together with a horizontal expansion by default.
how the content disappears; a fade out together with a horizontal shrink by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
A container that animates content in and out inside a Column, expanding and shrinking vertically only, so the column's width does not change.
Otherwise behaves as the ConstrainedScope overload.
Parameters
whether the content is shown.
the SwingModifier applied to the container.
how the content appears; a fade in together with a vertical expansion by default.
how the content disappears; a fade out together with a vertical shrink by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
A container that animates content in and out as visibleState's target state changes. MutableTransitionState.isIdle tells whether every animation has finished, and MutableTransitionState.currentState where the running one started.
A state whose target is set to true when it is mounted enters from MutableTransitionState.currentState instead of appearing at once, which the Boolean overload cannot express. Keep one instance across compositions; a new instance snaps to the state it declares.
Otherwise behaves as the Boolean overload.
Parameters
whether the content is shown, and the state the transition is read back through.
the SwingModifier applied to the container.
how the content appears; a fade in together with an expansion from nothing by default.
how the content disappears; a fade out together with a shrink to nothing by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
The MutableTransitionState counterpart of the Boolean overload inside a Foundation layout.
Otherwise behaves as the ConstrainedScope overload taking a Boolean.
Parameters
whether the content is shown, and the state the transition is read back through.
the SwingModifier applied to the container.
how the content appears; a fade in together with an expansion from nothing by default.
how the content disappears; a fade out together with a shrink to nothing by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
The MutableTransitionState counterpart of the Row overload.
Otherwise behaves as the Boolean Row overload.
Parameters
whether the content is shown, and the state the transition is read back through.
the SwingModifier applied to the container.
how the content appears; a horizontal expansion together with a fade in by default.
how the content disappears; a horizontal shrink together with a fade out by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
The MutableTransitionState counterpart of the Column overload.
Otherwise behaves as the Boolean Column overload.
Parameters
whether the content is shown, and the state the transition is read back through.
the SwingModifier applied to the container.
how the content appears; a vertical expansion together with a fade in by default.
how the content disappears; a vertical shrink together with a fade out by default.
names the transition in a tool that inspects a composition.
the composable content of the container; see AnimatedVisibilityScope.
fun <T> Transition<T>.AnimatedVisibility(visible: (T) -> Boolean, modifier: SwingModifier = SwingModifier, enter: EnterTransition = fadeIn() + expandIn(), exit: ExitTransition = shrinkOut() + fadeOut(), content: @Composable AnimatedVisibilityScope.() -> Unit)
A container that animates content in and out as this transition's state starts and stops satisfying visible. Containers built on one transition animate together.
val transition = updateTransition(page)
transition.AnimatedVisibility(visible = { it == Page.Details }) { Details() }
transition.AnimatedVisibility(visible = { it == Page.Summary }) { Summary() }On a deferred transition, which announces its next state before animating to it, the container composes the announced content at EnterExitState.PreEnter, so it is measured before the enter starts. The enter runs when the deferred phase ends. If the phase ends without reaching the announced state, that content is removed.
Otherwise behaves as the Boolean overload. Requires a ConstrainedScope.
Parameters
whether the content is shown for a given state of this transition.
the SwingModifier applied to the container.
how the content appears; a fade in together with an expansion from nothing by default.
how the content disappears; a shrink to nothing together with a fade out by default.
the composable content of the container; see AnimatedVisibilityScope.