Function Signature
Parameters
The index of the snap point to snap to (0-based, sorted ascending)
- Must be within the range
0tosnapPoints.length - 1 - Snap points are automatically sorted in ascending order
- Index
0always refers to the smallest snap point - Index
snapPoints.length - 1refers to the largest snap point
Return Value
This function does not return a value. It triggers an animation to snap the screen to the specified snap point.
Usage
Basic Example
Multi-Stop Sheet
Screen Configuration
ForsnapTo() to work, the target screen must be configured with snap points:
The
snapTo() function only works on screens that have snapPoints configured in their options.Behavior
- Sorting: Snap points are automatically sorted in ascending order internally. You always reference them by their sorted index.
- Animation: The transition uses the
expandorcollapseanimation spec defined intransitionSpec - Current Screen: Only affects the currently focused screen with snap points
- Invalid Index: Logs a warning if the index is out of bounds
- No Snap Points: Logs a warning if the target screen has no snap points configured
Animation Customization
Customize snap animations usingtransitionSpec:
Use Cases
Bottom Sheets
Control sheet expansion from buttons or gestures
Side Panels
Snap drawers to different widths
Top Sheets
Expand notifications or controls from the top
Multi-State Modals
Create modals with multiple expansion states
