SearchBarState
@ExperimentalMaterial3Api
class SearchBarState
private constructor(
private val animatable: Animatable<Float, AnimationVector1D>,
private val animationSpecForExpand: AnimationSpec<Float>,
private val animationSpecForCollapse: 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),
animationSpecForExpand = animationSpecForExpand,
animationSpecForCollapse = animationSpecForCollapse,
)
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. |
Properties
var collapsedCoords: LayoutCoordinates?
The layout coordinates, if available, of the search bar when it is collapsed. Used to coordinate the expansion animation.
@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
.
val isAnimating: Boolean
Whether the state is currently animating
val targetValue: SearchBarValue
Whether the search bar is going to be expanded or collapsed.
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
suspend fun animateToExpanded()
Animate the search bar to its expanded state.
suspend fun animateToCollapsed()
Animate the search bar to its collapsed state.
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
fun Saver(
animationSpecForExpand: AnimationSpec<Float>,
animationSpecForCollapse: AnimationSpec<Float>,
): Saver<SearchBarState, *>
The default Saver
implementation for SearchBarState
.