public object TopAppBarDefaults
Contains default values used for the top app bar implementations.
Properties
ContentPadding
public val ContentPadding: PaddingValues = PaddingValues(all = 0.dp)
Default padding used for TopAppBar content
windowInsets
public val windowInsets: WindowInsets
Default insets to be used and consumed by the top app bars
snapAnimationSpec
public val snapAnimationSpec: AnimationSpec<Float>
Default AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position.
flingAnimationSpec
public val flingAnimationSpec: DecayAnimationSpec<Float>
Default DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content.
TopAppBarExpandedHeight
public val TopAppBarExpandedHeight: Dp = AppBarSmallTokens.ContainerHeight
The default expanded height of a TopAppBar and the CenterAlignedTopAppBar.
MediumAppBarCollapsedHeight
public val MediumAppBarCollapsedHeight: Dp = AppBarSmallTokens.ContainerHeight
The default height of a MediumTopAppBar when collapsed by a TopAppBarScrollBehavior.
MediumAppBarExpandedHeight
public val MediumAppBarExpandedHeight: Dp = AppBarMediumTokens.ContainerHeight
The default expanded height of a MediumTopAppBar.
MediumFlexibleAppBarWithoutSubtitleExpandedHeight
public val MediumFlexibleAppBarWithoutSubtitleExpandedHeight: Dp =
AppBarMediumFlexibleTokens.ContainerHeight
The default expanded height of a MediumFlexibleTopAppBar without subtitle.
MediumFlexibleAppBarWithSubtitleExpandedHeight
public val MediumFlexibleAppBarWithSubtitleExpandedHeight: Dp =
AppBarMediumFlexibleTokens.LargeContainerHeight
The default expanded height of a MediumFlexibleTopAppBar with subtitle.
LargeAppBarCollapsedHeight
public val LargeAppBarCollapsedHeight: Dp = AppBarSmallTokens.ContainerHeight
The default height of a LargeTopAppBar when collapsed by a TopAppBarScrollBehavior.
LargeAppBarExpandedHeight
public val LargeAppBarExpandedHeight: Dp = AppBarLargeTokens.ContainerHeight
The default expanded height of a LargeTopAppBar.
LargeFlexibleAppBarWithoutSubtitleExpandedHeight
public val LargeFlexibleAppBarWithoutSubtitleExpandedHeight: Dp =
AppBarLargeFlexibleTokens.ContainerHeight
The default expanded height of a LargeFlexibleTopAppBar without subtitle.
LargeFlexibleAppBarWithSubtitleExpandedHeight
public val LargeFlexibleAppBarWithSubtitleExpandedHeight: Dp =
AppBarLargeFlexibleTokens.LargeContainerHeight
The default expanded height of a LargeFlexibleTopAppBar with subtitle.
Functions
topAppBarColors
@Composable
public fun topAppBarColors(): TopAppBarColors
Creates a TopAppBarColors for small TopAppBar. The default implementation animates between the provided colors according to the Material Design specification.
topAppBarColors
@Composable
public fun topAppBarColors(
containerColor: Color = Color.Unspecified,
scrolledContainerColor: Color = Color.Unspecified,
navigationIconContentColor: Color = Color.Unspecified,
titleContentColor: Color = Color.Unspecified,
actionIconContentColor: Color = Color.Unspecified,
subtitleContentColor: Color = Color.Unspecified,
): TopAppBarColors
Creates a TopAppBarColors for small TopAppBar. The default implementation animates between the provided colors according to the Material Design specification.
Parameters
| containerColor | the container color |
| scrolledContainerColor | the container color when content is scrolled behind it |
| navigationIconContentColor | the content color used for the navigation icon |
| titleContentColor | the content color used for the title |
| actionIconContentColor | the content color used for actions |
| subtitleContentColor | the content color used for the subtitle |
Return
the resulting TopAppBarColors used for the top app bar
topAppBarColors
@Deprecated(
"Maintained for binary compatibility in favor of topAppBarColors with subtitleContentColor",
level = DeprecationLevel.HIDDEN,
)
@Composable
public fun topAppBarColors(
containerColor: Color = Color.Unspecified,
scrolledContainerColor: Color = Color.Unspecified,
navigationIconContentColor: Color = Color.Unspecified,
titleContentColor: Color = Color.Unspecified,
actionIconContentColor: Color = Color.Unspecified,
): TopAppBarColors
Creates a TopAppBarColors for small TopAppBar. The default implementation animates between the provided colors according to the Material Design specification.
Parameters
| containerColor | the container color |
| scrolledContainerColor | the container color when content is scrolled behind it |
| navigationIconContentColor | the content color used for the navigation icon |
| titleContentColor | the content color used for the title |
| actionIconContentColor | the content color used for actions |
Return
the resulting TopAppBarColors used for the top app bar
centerAlignedTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith = ReplaceWith("topAppBarColors()"),
DeprecationLevel.WARNING,
)
@Composable
public fun centerAlignedTopAppBarColors(): TopAppBarColors
Creates a TopAppBarColors for CenterAlignedTopAppBars. The default implementation animates between the provided colors according to the Material Design specification.
centerAlignedTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith =
ReplaceWith(
"topAppBarColors(containerColor, scrolledContainerColor, " +
"navigationIconContentColor, titleContentColor, actionIconContentColor)"
),
DeprecationLevel.WARNING,
)
@Composable
public fun centerAlignedTopAppBarColors(
containerColor: Color = Color.Unspecified,
scrolledContainerColor: Color = Color.Unspecified,
navigationIconContentColor: Color = Color.Unspecified,
titleContentColor: Color = Color.Unspecified,
actionIconContentColor: Color = Color.Unspecified,
): TopAppBarColors
Creates a TopAppBarColors for CenterAlignedTopAppBars. The default implementation animates between the provided colors according to the Material Design specification.
Parameters
| containerColor | the container color |
| scrolledContainerColor | the container color when content is scrolled behind it |
| navigationIconContentColor | the content color used for the navigation icon |
| titleContentColor | the content color used for the title |
| actionIconContentColor | the content color used for actions |
Return
the resulting TopAppBarColors used for the top app bar
mediumTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith = ReplaceWith("topAppBarColors()"),
DeprecationLevel.WARNING,
)
@Composable
public fun mediumTopAppBarColors(): TopAppBarColors
Creates a TopAppBarColors for MediumTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.
mediumTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith =
ReplaceWith(
"topAppBarColors(containerColor, scrolledContainerColor, " +
"navigationIconContentColor, titleContentColor, actionIconContentColor)"
),
DeprecationLevel.WARNING,
)
@Composable
public fun mediumTopAppBarColors(
containerColor: Color = Color.Unspecified,
scrolledContainerColor: Color = Color.Unspecified,
navigationIconContentColor: Color = Color.Unspecified,
titleContentColor: Color = Color.Unspecified,
actionIconContentColor: Color = Color.Unspecified,
): TopAppBarColors
Creates a TopAppBarColors for MediumTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.
Parameters
| containerColor | the container color |
| scrolledContainerColor | the container color when content is scrolled behind it |
| navigationIconContentColor | the content color used for the navigation icon |
| titleContentColor | the content color used for the title |
| actionIconContentColor | the content color used for actions |
Return
the resulting TopAppBarColors used for the top app bar
largeTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith = ReplaceWith("topAppBarColors()"),
DeprecationLevel.WARNING,
)
@Composable
public fun largeTopAppBarColors(): TopAppBarColors
Creates a TopAppBarColors for LargeTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.
largeTopAppBarColors
@Deprecated(
"Use topAppBarColors instead",
replaceWith =
ReplaceWith(
"topAppBarColors(containerColor, scrolledContainerColor, " +
"navigationIconContentColor, titleContentColor, actionIconContentColor)"
),
DeprecationLevel.WARNING,
)
@Composable
public fun largeTopAppBarColors(
containerColor: Color = Color.Unspecified,
scrolledContainerColor: Color = Color.Unspecified,
navigationIconContentColor: Color = Color.Unspecified,
titleContentColor: Color = Color.Unspecified,
actionIconContentColor: Color = Color.Unspecified,
): TopAppBarColors
Creates a TopAppBarColors for LargeTopAppBars. The default implementation interpolates between the provided colors as the top app bar scrolls according to the Material Design specification.
Parameters
| containerColor | the container color |
| scrolledContainerColor | the container color when content is scrolled behind it |
| navigationIconContentColor | the content color used for the navigation icon |
| titleContentColor | the content color used for the title |
| actionIconContentColor | the content color used for actions |
Return
the resulting TopAppBarColors used for the top app bar
pinnedScrollBehavior
@Composable
public fun pinnedScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly. Note: If your layout utilizes reverseLayout or reverseScrolling, please use the overload that takes a ScrollableState parameter.
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior |
pinnedScrollBehavior
@Deprecated(
message =
"Please use the pinnedScrollBehavior function that takes a ScrollableState parameter.",
replaceWith =
ReplaceWith(
"pinnedScrollBehavior(scrollableState = lazyListState, state = state, canScroll = canScroll)"
),
level = DeprecationLevel.WARNING,
)
@Composable
public fun pinnedScrollBehavior(
lazyListState: LazyListState,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.
This overload is intended for use cases with LazyColumn when the content is pre-scrolled or uses reverseLayout, as it correctly handles TopAppBar color transitions for these specific scroll states.
The returned TopAppBarScrollBehavior is remembered across compositions.
A sample for a pinned small TopAppBar when the content of the LazyColumn is pre-scrolled:
Parameters
| lazyListState | the LazyListState object observing the list's scroll position, used to determine if the list is scrolled to the start |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions |
| canScroll | a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior |
pinnedScrollBehavior
@Deprecated(
message =
"Please use the pinnedScrollBehavior function that takes a ScrollableState parameter.",
replaceWith =
ReplaceWith(
"pinnedScrollBehavior(scrollableState = scrollState, state = state, canScroll = canScroll)"
),
level = DeprecationLevel.WARNING,
)
@Composable
public fun pinnedScrollBehavior(
scrollState: ScrollState,
reverseScrolling: Boolean = false,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.
This overload is intended for use cases with composables that use a ScrollState, such as Column with verticalScroll, especially when the content is pre-scrolled or uses reverseScrolling. It correctly handles TopAppBar color transitions for these specific scroll states.
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| scrollState | state of the scroll |
| reverseScrolling | reverse the direction of scrolling, when true, 0 ScrollState.value will mean bottom, when false, 0 ScrollState.value will mean top |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions |
| canScroll | a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior |
pinnedScrollBehavior
@Deprecated(
message =
"Please use the pinnedScrollBehavior function that takes a ScrollableState parameter.",
level = DeprecationLevel.WARNING,
)
@Composable
public fun pinnedScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
isScrollingContentAtStart: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.
This overload is intended for use cases that are not covered by the standard overloads, such as when a custom isScrollingContentAtStart state needs to be determined for custom or complex layouts (e.g. LazyVerticalGrid with reverseLayout = true).
The returned TopAppBarScrollBehavior is remembered across compositions.
A sample for a pinned small TopAppBar that is scrolled with a reversed LazyVerticalGrid:
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions |
| canScroll | a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior |
| isScrollingContentAtStart | A callback that returns true when the scrollable is at the origin of its content. Handles reversed layouts to ensure "start" always refers to the first logical item. |
pinnedScrollBehavior
@Composable
public fun pinnedScrollBehavior(
scrollableState: ScrollableState,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a pinned TopAppBarScrollBehavior that tracks nested-scroll callbacks and updates its TopAppBarState.contentOffset accordingly.
This overload is intended for use cases where the scroll state is represented by a ScrollableState (e.g. LazyVerticalGrid). It automatically determines if the content is at the start by observing the scroll position of the provided ScrollableState.
The returned TopAppBarScrollBehavior is remembered across compositions.
A sample for a pinned small TopAppBar that is scrolled with a reversed LazyVerticalGrid:
Parameters
| scrollableState | the ScrollableState of the scrollable container, used to determine if the content is at the start |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions |
| canScroll | a callback used to determine whether scroll events are to be handled by this pinned TopAppBarScrollBehavior |
enterAlwaysScrollBehavior
@Composable
public fun enterAlwaysScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down. Note: If your layout utilizes reverseLayout or reverseScrolling, please use the overload that takes a ScrollableState parameter.
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this TopAppBarScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
enterAlwaysScrollBehavior
@Deprecated(
message =
"Please use the enterAlwaysScrollBehavior() function that takes a scrollableState parameter.",
replaceWith =
ReplaceWith(
"enterAlwaysScrollBehavior(scrollableState, state, canScroll, snapAnimationSpec, flingAnimationSpec)"
),
level = DeprecationLevel.WARNING,
)
@Composable
public fun enterAlwaysScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
reverseLayout: Boolean = false,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this EnterAlwaysScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
| reverseLayout | indicates that this behavior is applied to a scrollable content that has a reversed direction of scrolling and layout |
enterAlwaysScrollBehavior
@Deprecated(
message =
"Please use the enterAlwaysScrollBehavior function that takes a ScrollableState parameter.",
replaceWith =
ReplaceWith(
"enterAlwaysScrollBehavior(scrollableState = lazyListState, state = state, canScroll = canScroll, snapAnimationSpec = snapAnimationSpec, flingAnimationSpec = flingAnimationSpec)"
),
level = DeprecationLevel.WARNING,
)
@Composable
public fun enterAlwaysScrollBehavior(
lazyListState: LazyListState,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.
This overload is intended for use cases with LazyColumn when the content is pre-scrolled or uses reverseLayout, as it correctly handles TopAppBar color transitions for these specific scroll states.
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| lazyListState | the LazyListState object observing the list's scroll position, used to determine if the list is scrolled to the start |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this TopAppBarScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
enterAlwaysScrollBehavior
@Deprecated(
message =
"Please use the enterAlwaysScrollBehavior function that takes a ScrollableState parameter.",
replaceWith =
ReplaceWith(
"enterAlwaysScrollBehavior(scrollableState = scrollState, state = state, canScroll = canScroll, snapAnimationSpec = snapAnimationSpec, flingAnimationSpec = flingAnimationSpec)"
),
level = DeprecationLevel.WARNING,
)
@Composable
public fun enterAlwaysScrollBehavior(
scrollState: ScrollState,
reverseScrolling: Boolean = false,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.
This overload is intended for use cases with composables that use a ScrollState, such as Column with verticalScroll, especially when the content is pre-scrolled or uses reverseScrolling. It correctly handles TopAppBar color transitions for these specific scroll states.
The returned TopAppBarScrollBehavior is remembered across compositions.
A sample for a small TopAppBar that collapses when the content is scrolled up, and appears when the content is scrolled down, using a Column with reverse scrolling:
Parameters
| scrollState | state of the scroll |
| reverseScrolling | reverse the direction of scrolling, when true, 0 ScrollState.value will mean bottom, when false, 0 ScrollState.value will mean top |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this TopAppBarScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
enterAlwaysScrollBehavior
@Deprecated(
message =
"Please use the enterAlwaysScrollBehavior function that takes a ScrollableState parameter.",
level = DeprecationLevel.WARNING,
)
@Composable
public fun enterAlwaysScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
isScrollingContentAtStart: () -> Boolean = { true },
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.
This overload is intended for use cases that are not covered by the standard overloads, such as when a custom isScrollingContentAtStart state needs to be determined for custom or complex layouts (e.g. LazyVerticalGrid with reverseLayout = true).
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this TopAppBarScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
| isScrollingContentAtStart | A callback that returns true when the scrollable is at the origin of its content. Handles reversed layouts to ensure "start" always refers to the first logical item. |
enterAlwaysScrollBehavior
@Composable
public fun enterAlwaysScrollBehavior(
scrollableState: ScrollableState,
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior. A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the content is pulled up, and will immediately appear when the content is pulled down.
This overload is intended for use cases with scrollable containers (such as LazyColumn, a Column with verticalScroll, or any other container that implements ScrollableState) when the content is pre-scrolled or uses reverseLayout/reverseScrolling, as it correctly handles TopAppBar color transitions for these specific scroll states.
An enter always top app bar with reverse scrolling looks like:
The returned TopAppBarScrollBehavior is remembered across compositions.
Parameters
| scrollableState | the ScrollableState of the scrollable container, used to determine if the content is at the start |
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this TopAppBarScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |
exitUntilCollapsedScrollBehavior
@Composable
public fun exitUntilCollapsedScrollBehavior(
state: TopAppBarState = rememberTopAppBarState(),
canScroll: () -> Boolean = { true },
snapAnimationSpec: AnimationSpec<Float>? = TopAppBarDefaults.snapAnimationSpec,
flingAnimationSpec: DecayAnimationSpec<Float>? = TopAppBarDefaults.flingAnimationSpec,
): TopAppBarScrollBehavior
Returns a TopAppBarScrollBehavior that adjusts its properties to affect the colors and height of the top app bar.
A top app bar that is set up with this TopAppBarScrollBehavior will immediately collapse when the nested content is pulled up, and will expand back the collapsed area when the content is pulled all the way down.
The returned TopAppBarScrollBehavior is remembered across compositions.
A sample for a MediumTopAppBar with exitUntilCollapsedScrollBehavior:
Parameters
| state | the state object to be used to control or observe the top app bar's scroll state. See rememberTopAppBarState for a state that is remembered across compositions. |
| canScroll | a callback used to determine whether scroll events are to be handled by this ExitUntilCollapsedScrollBehavior |
| snapAnimationSpec | an optional AnimationSpec that defines how the top app bar snaps to either fully collapsed or fully extended state when a fling or a drag scrolled it into an intermediate position. If null is provided, the app bar will not snap and will remain in its current state. |
| flingAnimationSpec | an optional DecayAnimationSpec that defines how to fling the top app bar when the user flings the app bar itself, or the scrollable content. If null is provided, the app bar will not continue to animate its height based on the scroll velocity. |