Overlays Overview
Overlays allow screens to appear on top of other screens while maintaining proper gesture and event handling. They’re used for modals, sheets, alerts, and popovers.Creating an Overlay
UseTransition.Modal to present content as an overlay:
Modal vs Stack Screens
| Aspect | Stack | Modal |
|---|---|---|
| Presentation | Push/pop | Overlay |
| Z-index | Sequential | Above everything |
| Snap points | Not applicable | Supported |
| Back button | Returns to prev screen | Dismisses |
| Backdrop | Optional | Default |
| Gesture | Full-screen drag | Swipe to dismiss |
Snap Points for Overlays
Modal overlays typically use snap points for sheet-like behavior:Animating Overlays
Define custom animations for overlays:Multiple Overlays
Stack multiple overlays:Interactive Backdrop
Allow users to dismiss overlays by tapping the backdrop:- Tap the backdrop to dismiss
- Swipe/drag to dismiss
- Interact with content
Custom Backdrop Component
Provide a custom backdrop renderer:Overlay Gestures
Control overlay gesture behavior:Preventing Interaction Below
SetpointerEvents to prevent touches from reaching underlying screens:
Overlay from Context Menu
Present an overlay triggered by context menu action:Alert-Style Overlay
Simple centered overlay with minimal snap point:Popover Overlay
Floating popover at specific position:Overlay Nesting
Overlays can present other overlays:Programmatic Navigation to Overlays
Dismissing Overlays
Several ways to dismiss an overlay:Overlay With Scroll
Combine overlays with scrollable content:Overlay Transitions Timing
Control animation duration:Best Practices
- Use snap points for sheet-style overlays
- Enable gesture for better UX (unless modal alert)
- Interactive backdrop for dismiss affordance
- Limit nesting depth to 2-3 overlays max
- Test gesture conflicts with underlying screens
- Provide visual feedback for interactive state
Troubleshooting
Overlay Not Appearing
Check:- Modal is defined in navigator
- Navigation.navigate() uses correct screen name
- Modal is not conditionally hidden
Gestures Not Working
Ensure:gestureEnabledis truegestureDirectionmatches desired axispointerEventsnot blocking interaction
Backdrop Not Dismissing
Verify:backdropBehavior: "interactive"- Backdrop
onPresshandler exists pointerEventsallows touches
Next Steps
- Learn snap points for overlay sizing
- Explore gestures for interaction
- See custom animations for overlay effects
