SearchBarState
The state of a search bar.
SearchBarState
@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
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.
fun Saver(
animationSpecForExpand: AnimationSpec<Float>,
animationSpecForCollapse: AnimationSpec<Float>,
animationSpecForContentFadeIn: AnimationSpec<Float>,
animationSpecForContentFadeOut: AnimationSpec<Float>,
): Saver<SearchBarState, *>
The default Saver implementation for SearchBarState.