Class

SearchBarState

The state of a search bar.

Source set: Common
@ExperimentalMaterial3Api
class SearchBarState
private constructor(
    internal val animatable: Animatable<Float, AnimationVector1D>,
    private val contentAnimatable: Animatable<Float, AnimationVector1D>,
    internal val animationSpecForExpand: AnimationSpec<Float>,
    internal val animationSpecForCollapse: AnimationSpec<Float>,
    private val animationSpecForContentFadeIn: AnimationSpec<Float>,
    private val animationSpecForContentFadeOut: AnimationSpec<Float>,
)

The state of a search bar.

Secondary Constructors

constructor(
    initialValue: SearchBarValue,
    animationSpecForExpand: AnimationSpec<Float>,
    animationSpecForCollapse: AnimationSpec<Float>,
) : this(
    animatable =
        Animatable(if (initialValue == SearchBarValue.Expanded) Expanded else Collapsed),
    contentAnimatable =
        Animatable(if (initialValue == SearchBarValue.Expanded) Expanded else Collapsed),
    animationSpecForExpand = animationSpecForExpand,
    animationSpecForCollapse = animationSpecForCollapse,
    animationSpecForContentFadeIn = snap(),
    animationSpecForContentFadeOut = snap(),
)

Construct a SearchBarState.

Parameters

initialValue the initial value of whether the search bar is collapsed or expanded.
animationSpecForExpand the animation spec used when the search bar expands.
animationSpecForCollapse the animation spec used when the search bar collapses.
constructor(
    initialValue: SearchBarValue,
    animationSpecForExpand: AnimationSpec<Float>,
    animationSpecForCollapse: AnimationSpec<Float>,
    animationSpecForContentFadeIn: AnimationSpec<Float>,
    animationSpecForContentFadeOut: AnimationSpec<Float>,
) : this(
    animatable =
        Animatable(if (initialValue == SearchBarValue.Expanded) Expanded else Collapsed),
    contentAnimatable =
        Animatable(if (initialValue == SearchBarValue.Expanded) Expanded else Collapsed),
    animationSpecForExpand = animationSpecForExpand,
    animationSpecForCollapse = animationSpecForCollapse,
    animationSpecForContentFadeIn = animationSpecForContentFadeIn,
    animationSpecForContentFadeOut = animationSpecForContentFadeOut,
)

Construct a SearchBarState.

Parameters

initialValue the initial value of whether the search bar is collapsed or expanded.
animationSpecForExpand the animation spec used when the search bar expands.
animationSpecForCollapse the animation spec used when the search bar collapses.
animationSpecForContentFadeIn the animation spec used for the content when the search bar expands.
animationSpecForContentFadeOut the animation spec used for the content when the search bar collapses.

Properties

collapsedCoords

Source set: Common
var collapsedCoords: LayoutCoordinates?

The layout coordinates, if available, of the search bar when it is collapsed. Used to coordinate the expansion animation.

progress

Source set: Common
@get:FloatRange(from = 0.0, to = 1.0)
val progress: Float

The animation progress of the search bar, where 0 represents SearchBarValue.Collapsed and 1 represents SearchBarValue.Expanded.

isAnimating

Source set: Common
val isAnimating: Boolean

Whether the state is currently animating

targetValue

Source set: Common
val targetValue: SearchBarValue

Whether the search bar is going to be expanded or collapsed.

currentValue

Source set: Common
val currentValue: SearchBarValue

Whether the search bar is currently expanded or collapsed. If the search bar is currently animating to/from the expanded state, currentValue is SearchBarValue.Expanded until the animation completes.

Functions

animateToExpanded

suspend fun animateToExpanded()

Animate the search bar to its expanded state.

animateToCollapsed

suspend fun animateToCollapsed()

Animate the search bar to its collapsed state.

snapTo

suspend fun snapTo(fraction: Float)

Snap the search bar progress to the given fraction, where 0 represents SearchBarValue.Collapsed and 1 represents SearchBarValue.Expanded.

Companion Object

Methods

Source set: Common
fun Saver(
            animationSpecForExpand: AnimationSpec<Float>,
            animationSpecForCollapse: AnimationSpec<Float>,
        ): Saver<SearchBarState, *>

The default Saver implementation for SearchBarState.

Source set: Common
fun Saver(
            animationSpecForExpand: AnimationSpec<Float>,
            animationSpecForCollapse: AnimationSpec<Float>,
            animationSpecForContentFadeIn: AnimationSpec<Float>,
            animationSpecForContentFadeOut: AnimationSpec<Float>,
        ): Saver<SearchBarState, *>

The default Saver implementation for SearchBarState.

Last updated: