animateVisibility

fun Modifier.animateVisibility(index: Int? = null, style: EntranceStyle = LocalEntranceStyle.current, staggerDelay: Int = 50, maxStaggeredItems: Int = 16): Modifier(source)

Brings a composable into place as its screen is shown, in a cascade.

Inside a ScreenHost the screen owns the cascade: elements wait until the screen settles, its transition over, then arrive one after another in their order on screen. Give list items their index and each waits staggerDelay per position after the first item shown, up to maxStaggeredItems positions; leave it out and elements cascade in the order they appear. An item a scroll brings into view enters at once, on the fast springs, outside the cascade. By default an element enters each time its screen is opened, and not on going back to it; LocalEntranceReplay can replay it on every return (EntranceReplay.EveryVisit) or play it only for the first copy of each screen in a run (EntranceReplay.FirstVisit). Returning from the background, rotating or scrolling back within the visit never does.

LazyColumn {
itemsIndexed(rows, key = { _, row -> row.id }) { index, row ->
RowCard(row, modifier = Modifier.animateItem().animateVisibility(index = index))
}
}

Outside a ScreenHost the element enters once, when it is first placed, in an app-wide cascade. Either way the entrance starts on placement, so an item a lazy list composes ahead of time still enters on screen. The motion follows MaterialTheme.motionScheme, its default spatial spring for the movement and its slow effects spring for the fade, so the app's MotionTempo sets the pace. It runs in the draw phase without recomposing. When animations are turned off system-wide, or style is EntranceStyle.None, the element simply appears.

Parameters

index

The element's position in its list, which orders it within the cascade.

style

How it enters; by default the app's LocalEntranceStyle.

staggerDelay

Delay added per position in the cascade, in milliseconds.

maxStaggeredItems

Positions past this one wait no longer than it does.


fun Modifier.animateVisibility(visible: Boolean, style: EntranceStyle = LocalEntranceStyle.current): Modifier(source)

Shows the composable while visible and hides it otherwise, animating both ways with style's motion: an element that comes and goes, such as a filter's result or a hint. It keeps its place in the layout while hidden, only drawn transparent; remove it from the layout with AnimatedVisibility instead.