### Install ActionSheet with npm
Source: https://rnas.vercel.app/installation
Install the ActionSheet library using npm. Ensure you have a package manager like npm installed.
```bash
npm install react-native-actions-sheet
```
--------------------------------
### React Native App Setup with ActionSheet
Source: https://rnas.vercel.app/
This snippet shows the basic setup for a React Native application integrating react-native-actions-sheet. It includes necessary providers for gesture handling, safe area context, and the SheetProvider itself.
```javascript
import {Sheets} from './app/sheets';
import {SheetProvider} from 'react-native-actions-sheet';
import MainScreen from './app/examples';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {SafeAreaProvider} from 'react-native-safe-area-context';
const App = () => {
return (
<>
>
);
};
export default App;
```
--------------------------------
### Install Dependencies with npm
Source: https://rnas.vercel.app/installation
Install the required dependencies for ActionSheet: react-native-reanimated, react-native-gesture-handler, and react-native-safe-area-context using npm.
```bash
npm install react-native-reanimated react-native-gesture-handler react-native-safe-area-context
```
--------------------------------
### Install Dependencies for v0.9.0
Source: https://rnas.vercel.app/guides/migrate
Install react-native-gesture-handlers as a dependency for v0.9.0.
```bash
npm install react-native-gesture-handlers
```
--------------------------------
### Install Dependencies for v10.0.0
Source: https://rnas.vercel.app/guides/migrate
Install react-native-reanimated and react-native-safe-area-context as peer dependencies for v10.0.0.
```bash
npm install react-native-reanimated react-native-safe-area-context
```
--------------------------------
### Import and Initialize ActionSheetRef
Source: https://rnas.vercel.app/reference/actionsheetref
Import ActionSheetRef and initialize a ref to null. This is the initial setup required before invoking any ActionSheetRef methods.
```typescript
import {ActionSheetRef} from 'react-native-actions-sheet';
const ref = useRef(null);
```
--------------------------------
### SheetDefinition Example
Source: https://rnas.vercel.app/reference/sheetdefinition
Example of declaring a SheetDefinition for 'example-sheet' with specific payload, returnValue, and routes.
```typescript
declare module 'react-native-actions-sheet' {
interface Sheets {
'example-sheet': SheetDefinition<{
payload: string;
returnValue: boolean;
routes: {
'route-1': RouteDefinition<{
param: 'param';
}>;
};
}>;
}
}
```
--------------------------------
### Show Sheet and Get Return Value
Source: https://rnas.vercel.app/guides/getdata
Use SheetManager.show to display a sheet and await its result. The result is the payload passed to SheetManager.hide.
```typescript
async function openExternalLink(link: string) {
const canOpen = await SheetManager.show('confirm-sheet', {
payload: {
message: `Do you want to open ${link} in your phone browser?`,
},
});
if (canOpen) {
Linking.openUrl(link);
}
}
```
--------------------------------
### Example Action Sheet Component
Source: https://rnas.vercel.app/reference/sheetprops
Demonstrates how to use SheetProps to access the sheet's ID and payload data within an ActionSheet component. The payload can be used to display dynamic content like a title.
```typescript
function ExampleSheet(props: SheetProps<"example-sheet">) {
return (
{props.payload?.title}
);
}
```
--------------------------------
### Integrate SheetProvider with Sheets Component
Source: https://rnas.vercel.app/reference/sheetregister
Wrap your application with SheetProvider and include the Sheets component to enable sheet functionality. This setup is necessary for all sheets registered via SheetRegister to work correctly.
```typescript
import {SheetProvider} from 'react-native-actions-sheet';
import {Sheets} from 'sheets.tsx';
function App() {
return (
{
// your app components
}
);
}
```
--------------------------------
### Accessing and Using Sheet Reference
Source: https://rnas.vercel.app/reference/usesheetref
Use the useSheetRef hook to get the reference to the current sheet. This reference can then be used to call methods like hide() on the sheet.
```javascript
// Some where in your sheet's component tree.
const ref = useSheetRef("example-sheet");
// Use methods on the current sheet.
ref.hide();
```
--------------------------------
### Define Sheet ID for Intellisense
Source: https://rnas.vercel.app/guides/migrate
Optionally define the exact sheet id directly in ActionSheet to get intellisense for payload/returnValue etc.
```typescript
{
// data is fully typed based on SheetDefinition of example-sheet.
}}
/>
```
--------------------------------
### Get Action Sheet Ref
Source: https://rnas.vercel.app/reference/sheetmanager
Retrieves the internal reference for an action sheet, allowing direct invocation of methods defined in `ActionSheetRef`. An optional context can be provided for sheets within specific `SheetProvider` instances.
```javascript
SheetManager.get('example-sheet')?.snapToOffset(25);
// or inside some modal with it's own `SheetProvider`
SheetManager.get('example-sheet', 'local-context')?.snapToOffset(25);
```
--------------------------------
### Track ActionSheet Position
Source: https://rnas.vercel.app/guides/position
Use the `onChange` prop to get the current position of the ActionSheet. This is useful for showing or hiding background UI or elements within the ActionSheet when it reaches a certain point, like the top of the screen.
```javascript
{
const hasReachedTop = position === 100;
if (hasReachedTop) {
// Do something
}
}}
/>
```
--------------------------------
### Extend Internal Interfaces for Type Intellisense
Source: https://rnas.vercel.app/guides/migrate
Extend internal interfaces to define sheets and get better type intellisense across your codebase for v0.9.0.
```typescript
import {SheetDefinition} from 'react-native-actions-sheet';
declare module 'react-native-actions-sheet' {
interface Sheets {
'example-sheet': SheetDefinition,{
payload: {
userId: string;
};
returnValue: boolean;
};
'awesome-sheet': SheetDefinition;
}
}
```
--------------------------------
### Access ActionSheetRef in components using useSheetRef
Source: https://rnas.vercel.app/guides/refaccess
In components, use the useSheetRef hook to get a reference to an action sheet by its ID. This reference can then be used to call methods like snapToOffset or hide.
```typescript
const ref = useSheetRef("example-sheet");
ref.snapToOffset(50);
ref.hide();
```
--------------------------------
### Get Active Sheets
Source: https://rnas.vercel.app/reference/sheetmanager
Retrieves a list of all currently active (open) action sheets for a specified ID. This allows iterating through active sheets to perform actions on them, such as hiding a specific sheet based on its payload.
```javascript
const activeSheets = SheetManager.getActiveSheets('example-sheet');
for (const sheet of activeSheets) {
if (sheet.ref.current.currentPayload().id === 'custom-id') {
sheet.ref.current.hide();
}
}
```
--------------------------------
### Access ActionSheetRef globally
Source: https://rnas.vercel.app/guides/refaccess
Use SheetManager to get the topmost action sheet reference by its ID. This is useful for controlling sheets from outside of their immediate component context.
```typescript
SheetManager.get('example-sheet').snapToOffset(50);
```
--------------------------------
### Registering Action Sheets with SheetProvider
Source: https://rnas.vercel.app/reference/sheetprovider
Demonstrates how to register an action sheet with the global SheetProvider and how to register it with multiple providers, including nested contexts.
```javascript
// Normal action sheet that is used with the global sheet provider.
registerSheet("example-sheet", ExampleSheet);
// You can also register the action sheet with multiple sheet providers.
registerSheet(
"example-sheet-nested",
ExampleSheet,
"global",
"local",
"local-local"
);
```
--------------------------------
### Show Action Sheet
Source: https://rnas.vercel.app/reference/actionsheetref
Use the show method to display the action sheet. Ensure the ref is correctly initialized.
```typescript
ref.current?.show();
```
--------------------------------
### show
Source: https://rnas.vercel.app/reference/actionsheetref
Displays the action sheet to the user. This is the primary method for making the action sheet visible.
```APIDOC
## `show`
### Description
Show the action sheet.
### Method
Invoke
### Endpoint
ActionSheetRef.show()
### Code Example
```javascript
ref.current?.show();
```
```
--------------------------------
### Action Sheet Configuration
Source: https://rnas.vercel.app/reference/actionsheet
Configure the appearance and behavior of the Action Sheet.
```APIDOC
## `enableElevation`
Enable elevation on the action sheet container.
Type| Required
---|---
`boolean`| no
Default: `true`
## `elevation`
Set elevation to the ActionSheet container.
Type| Required
---|---
number| no
Default: `5`
## `overlayColor`
Color of the overlay/backdrop.
Type| Required
---|---
string| no
Default: `"black"`
## `defaultOverlayOpacity`
Default opacity of the overlay/backdrop.
Type| Required
---|---
number 0 - 1| no
Default: `0.3`
## `closable`
This will make sure that the action sheet remains open always after opened first time.
Type| Required
---|---
boolean| no
Default: `true`
## `statusBarTranslucent`
Determine whether the modal should go under the system statusbar.
Type| Required
---|---
boolean| no
Default: `true`
## `closeOnPressBack`
Will the ActionSheet close on `hardwareBackPress` event.
Type| Required
---|---
boolean| no
Default: `true`
## `drawUnderStatusBar`
Draw action sheet container under the status bar.
Type| Required
---|---
boolean| no
Default: `false`
## `overdrawEnabled`
When the action sheet is pulled beyond top position, it overdraws and bounces back. Set this to false if you need to disable this behaviour.
Type| Required
---|---
`boolean`| no
Default: `true`
## `overdrawFactor`
Set how quickly the sheet will overdraw on pulling beyond top position. A lower value means faster overdraw.
Type| Required
---|---
`number`| no
Default: `15`
## `overdrawSize`
Set the height of the overdraw View. If you set the `overdrawFactor` to a lower value, you should increase the size of the overdraw to prevent the action sheet from showing background views etc.
Type| Required
---|---
`number`| no
Default: `100`
## `useBottomSafeAreaPadding`
Apply padding to bottom based on device safe area insets.
Type| Required
---|---
`boolean`| no
Default: `false`
## `withNestedSheetProvider`
If any of the action sheets in a nested SheetProvider is not a modal, i.e uses `isModal={false}` then you must define the provider with this prop. This allows the action sheet to be rendered correctly in fullscreen.
Type| Required
---|---
`React.ReactNode`| no
## `disableElevation`
Disable elevation/shadow of the action sheet.
Type| Required
---|---
`boolean`| no
```
--------------------------------
### Action Sheet Routing and Navigation
Source: https://rnas.vercel.app/reference/actionsheet
Configure routing and navigation within the Action Sheet.
```APIDOC
## `routes`
A list of routes for this actions sheet if any.
Type| Required
---|---
`Route[]`| no
## `initialRoute`
Initial route to navigate to when the sheet opens.
Type| Required
---|---
string| no
## `enableRouterBackNavigation`
Enable back navigation for router when pressing hardware back button or touching the back drop. Remember that swiping down the sheet will still close the sheet regardless of the route in stack.
Type| Required
---|---
boolean| no
```
--------------------------------
### Import ActionSheet Component
Source: https://rnas.vercel.app/usage
Import the ActionSheet component and its ref type into your project. This is the first step to using ActionSheet.
```javascript
import ActionSheet, { ActionSheetRef } from "react-native-actions-sheet";
```
--------------------------------
### Use Bottom SafeArea Padding
Source: https://rnas.vercel.app/guides/safearea
Use `useBottomSafeAreaPadding` to automatically calculate bottom padding on mobile, preventing content from being hidden under the navigation bar.
```javascript
```
--------------------------------
### Action Sheet Advanced Configuration
Source: https://rnas.vercel.app/reference/actionsheet
Advanced configuration options for the Action Sheet, including safe area and gesture handling.
```APIDOC
## `backdropProps`
An object containing props for the backdrop layer. Used to provide accessibility props.
Type| Required
---|---
object| no
## `safeAreaInsets`
Default safeArea insets provided through a library such as `react-native-safe-area-insets`. This also helps in giving a tiny boost in performance as the sheet does not have to calculate insets anymore.
Type| Required
---|---
object| no
## `enableGesturesInScrollView`
Enable swipe gestures inside ScrollView/FlatList. Enabled by default.
Type| Required
---|---
boolean| no
## `initialTranslateFactor`
Set the initial translate factor of the action sheet when it opens. Default is `1` which means the action sheet will open from bottom of the screen. You can set it to `0.5` to have it open from half way of the screen.
Type| Required
---|---
number| no
Default: `1`
```
--------------------------------
### Show ActionSheet Programmatically
Source: https://rnas.vercel.app/usage
Present the ActionSheet to the user by invoking the `show` method on its attached ref. This action is typically triggered by a user interaction.
```javascript
actionSheetRef.current?.show();
```
--------------------------------
### ExampleSheet with overrideProps
Source: https://rnas.vercel.app/reference/showoptions
Demonstrates how to use overrideProps to customize an ActionSheet component within an ExampleSheet. The disableElevation and gestureEnabled props are overridden.
```typescript
function ExampleSheet(props: SheetProps<'example-sheet'>) {
return (
);
}
```
--------------------------------
### Show Action Sheet with Options and Payload
Source: https://rnas.vercel.app/reference/sheetmanager
Displays an action sheet with specific options and sends data to it. The payload is accessible within the action sheet component.
```javascript
const confirmed = await SheetManager.show('confirm-sheet', {
payload: {message: 'Do you want to open this link?'},
});
```
--------------------------------
### Opening a Sheet with Payload and Accessing it
Source: https://rnas.vercel.app/reference/usesheetpayload
Demonstrates how to open a sheet with specific payload data using SheetManager.open() and then access that payload within the sheet's component tree using the useSheetPayload hook.
```javascript
SheetManager.open("user-properties", {
payload: {
userId: 'user-id'
}
});
// Some where in your sheet's component tree.
const payload = useSheetPayload("user-properties");
// Access the values on the payload.
payload.userId
```
--------------------------------
### isOpen
Source: https://rnas.vercel.app/reference/actionsheetref
Checks the current open or closed state of the action sheet.
```APIDOC
## `isOpen`
### Description
Check if the action sheet is open or closed.
### Method
Get
### Endpoint
ActionSheetRef.isOpen()
```
--------------------------------
### Define and Use ActionSheet Router
Source: https://rnas.vercel.app/guides/sheetrouter
This snippet shows how to define routes and components for an ActionSheet router. It includes navigation between 'route-a' and 'route-b', and how to access route parameters.
```typescript
import ActionSheet,
Route,
RouteScreenProps,
useSheetRouter,
useSheetRouteParams,
} from 'react-native-actions-sheet';
const RouteA = ({router}: RouteScreenProps<"sheet-with-router", "route-a">) => {
return (
);
};
const RouteB = () => {
const router = useSheetRouter("sheet-with-router");
const params = useSheetRouteParams("sheet-with-router", "route-b");
return (
);
};
const routes: Route[] = [
{
name: 'route-a',
component: RouteA,
},
{
name: 'route-b',
component: RouteB,
},
];
function SheetWithRouter(props: SheetProps) {
return (
);
}
export default SheetWithRouter;
```
--------------------------------
### useRouter
Source: https://rnas.vercel.app/reference/userouter
A hook that helps you navigate between routes inside the sheet.
```APIDOC
## `currentRoute: Route`
The current navigation route in stack that has been navigated to.
## `navigate`
Navigate to a route
### Parameters
#### Path Parameters
- **name** (string) - Required - Name of the route to navigate to.
- **params** (any) - Optional - Any data to pass to the route during navigation.
- **snap** (-100 to 100) - Required - Snap value for navigation animation. Between -100 to 100. A positive value snaps inwards, while a negative value snaps outwards.
## `goBack`
Navigate back from a route.
### Parameters
#### Path Parameters
- **name** (string) - Optional - Name of the route to navigate to.
- **snap** (-100 to 100) - Required - Snap value for navigation animation. Between -100 to 100. A positive value snaps inwards, while a negative value snaps outwards.
## `close()`
Close the sheet.
## `popToTop()`
Pop to top of the stack.
## `hasRoutes()`
Check whether any routes have been registered with this sheet.
## `stack: Route[]`
Get the current rendered stack.
## `canGoBack()`
Check whether router can go back in navigation.
```
--------------------------------
### Snap to Index
Source: https://rnas.vercel.app/reference/actionsheetref
Snap the action sheet to a specific snap point index when multiple snap points are configured. The index must be a number.
```typescript
ref.current?.snapToIndex(1);
```
--------------------------------
### Showing a Sheet in a Specific Context
Source: https://rnas.vercel.app/guides/migrate
When opening a sheet registered with multiple contexts, specify the desired context using the 'context' option in the show method.
```typescript
SheetManager.show('sheet-id', {
context: 'context-b',
});
```
--------------------------------
### ActionSheet Props
Source: https://rnas.vercel.app/reference/actionsheet
Configuration options for the ActionSheet component.
```APIDOC
## ActionSheet Props
### `id`
A unique id for the action sheet that is required to present it from anywhere in the app using the `SheetManager`.
Type| Required
---|---
id| false
### `ref`
Set this ref if you need to use `ActionSheetRef` methods.
Type| Required
---|---
ref| false
### `testIDs`
An object containing test ids for various views in the actionSheet.
`modal`: 'Test id for the modal'
`root`: Test id for the root container when `isModal` is set to `false`.
`backdrop`: Test id for the backdrop. Can be used to close the action sheet in e2e tests.
`sheet`: Test id for the container that wraps all your components inside the sheet.
Type| Required
---|---
object| no
### `animated`
Disable all animations
Type| Required
---|---
boolean| no
Default: `true`
### `gestureEnabled`
Controls whether the gestures should be enabled on the action sheet.
Type| Required
---|---
boolean| no
Default: `false`
### `isModal`
Setting this to `false` will make the action sheet use an absolute positioned `View` as a container. This is automatically enabled when background interaction is enabled.
Type| Required
---|---
boolean| no
default:`true`
### `zIndex`
The default zIndex of wrapper `View` when `isModal` is set to `false` or background interaction is enabled is `9999`. You can change it here.
Type| Required
---|---
number| no
default:`9999`
### `returnValue`
Since `SheetManager.show` is now an async function that resolves when the action sheet closed, you can return some data to the caller by setting this prop. When the Sheet closes the promise will resolve with the data.
Type| Required
---|---
`any`| no
### `backgroundInteractionEnabled`
Enable background interation. This way the user will be able to interact with the UI elements in background of the action sheet when it is opened.
Type| Required
---|---
`boolean`| no
Default: `false`
### `snapPoints`
Provide snap points ranging from 0 to 100. ActionSheet will snap between these points. If no snap points are provided, the default is a single snap point set to `100` which means that the sheet will be opened 100% on becoming visible.
Note. `snapPoints` are relative to the height of the content inside ActionSheet. 100 = All content visible and 50 = half of the content is visible.
Type| Required
---|---
`number[]`| no
Default: `[100]`
### `initialSnapIndex`
When you have set the `snapPoints` prop. You can use this prop to set the inital snap point for the sheet. For example if i have snap points set to `[30,60,100]` then setting this prop to `1` would mean the action sheet will snap to 60% on becoming visible.
Type| Required
---|---
`number`| no
Default: `0`
### `indicatorStyle`
The top indicator bar on the action sheet is a regular `View` component and can be styles as such.
Type| Required
---|---
`StyleProp `| no
### `containerStyle`
Style the main container in the action sheet that wraps your content.
Note: You can set most styles here except `maxHeight`, `marginBottom` and `paddingBottom`. These are used internally. You can do this instead:
```
```
Type| Required
---|---
`StyleProp`| no
### `openAnimationConfig`
Modify the animation when the sheet opens.
Type| Required
---|---
`Animated.SpringAnimationConfig`| no
### `closeAnimationConfig`
Modify the animation when the sheet closes.
Type| Required
---|---
`Animated.SpringAnimationConfig`| no
### `CustomHeaderComponent`
A custom header component if any that replaces the default indicator bar on top.
Type| Required
---|---
React. ReactNode| no
### `ExtraOverlayComponent`
Render a component that is absolutely positioned over the action sheet. This is useful for rendering toasts & in-app notifications.
Type| Required
---|---
React. ReactNode| no
### `keyboardHandlerEnabled`
The action sheet uses it's own keyboard handling. Set this prop to false to disable it if needed.
Type| Required
---|---
`boolean`| no
### `headerAlwaysVisible`
By default when the `gesturesEnabled` prop is set to false, the top indicator bar or any custom header component is hidden. Set this to true to keep the header always visible.
Type| Required
---|---
boolean| no
Default: `false`
### `closeOnTouchBackdrop`
Should the action sheet close when touching the backdrop area above the action sheet.
Type| Required
---|---
boolean| no
Default: `true`
### `springOffset`
Choose how far off the user needs to drag the action sheet to make it snap to next point. The default is `50` which means that user needs to drag the sheet up or down at least 50 display pixels for it to close or move to next snap point. Otherwise it will just return to the initial position.
Type| Required
---|---
number| no
Default: `50`
```
--------------------------------
### Action Sheet Events and Callbacks
Source: https://rnas.vercel.app/reference/actionsheet
Handle events and callbacks for the Action Sheet component.
```APIDOC
## `onChange(positon:number)`
A function that is called whenever the action sheet moves with the current position. When the `position` value is `100` it means the action sheet has reached top.
Type| Required
---|---
function| no
## `onClose`
A function called when the action sheet closes
Type| Required
---|---
function| no
## `onOpen`
A function called when the action sheet opens.
Type| Required
---|---
function| no
## `onBeforeShow(data:any)`
A function called just before the action sheet is ready to be shown.
Type| Required
---|---
function| no
## `onBeforeClose(data:any)`
A function called just before the action sheet is closing.
Type| Required
---|---
function| no
## `onNavigate(route: string)`
An event called when navigating to a route in stack
Type| Required
---|---
function| no
## `onNavigateBack(route: string)`
An event called when navigating back in stack.
Type| Required
---|---
function| no
## `onTouchBackdrop`
A callback that gets invoked when user taps on the backdrop area.
Type| Required
---|---
function| no
## `onSnapIndexChange`
Callback invoked when the snap position of the sheet changes.
Type| Required
---|---
function| no
```
--------------------------------
### snapToOffset
Source: https://rnas.vercel.app/reference/actionsheetref
Snaps the action sheet to a specific offset defined as a percentage.
```APIDOC
## `snapToOffset`
### Description
Provide a value between `0` to `100` for the action sheet to snap to.
### Method
Invoke
### Endpoint
ActionSheetRef.snapToOffset(offset)
### Parameters
#### Path Parameters
- **offset** (number) - Required - A value between 0 to 100.
### Code Example
```javascript
ref.current?.snapToOffset(20);
```
```
--------------------------------
### Wrap App with SheetProvider
Source: https://rnas.vercel.app/guides/sheetmanager
In your App.tsx file, import the Sheets component and wrap your entire application within the SheetProvider. This makes SheetManager functionalities available throughout the app.
```typescript
import {SheetProvider} from 'react-native-actions-sheet';
import { Sheets } from 'sheets.tsx';
function App() {
return (
{
// your app components
}
);
}
```
--------------------------------
### Register ActionSheet with Router
Source: https://rnas.vercel.app/guides/sheetrouter
This snippet demonstrates how to register a sheet with its defined routes using `registerSheet`. It also includes TypeScript declarations for route parameters.
```typescript
import {registerSheet} from 'react-native-actions-sheet';
import {SheetWithRouter} from './sheet-with-router';
registerSheet('sheet-with-router', SheetWithRouter);
declare module 'react-native-actions-sheet' {
interface Sheets {
'sheet-with-router': SheetDefinition<{
routes: {
'route-a': RouteDefinition;
// Route B with params.
'route-b': RouteDefinition<{
data: string
}>;
};
}>;
}
}
```
--------------------------------
### Integrating FlashList in ActionSheet
Source: https://rnas.vercel.app/guides/flashlist
Import ActionSheet, ScrollView, and FlashList. Use FlashList with the renderScrollComponent prop set to ScrollView when nesting it within an ActionSheet.
```javascript
import ActionSheet, {ScrollView} from 'react-native-actions-sheet';
import {FlashList} from '@shopify/flash-list';
const ExampleSheet = () => {
return (
);
};
```
--------------------------------
### Show ActionSheet using SheetManager
Source: https://rnas.vercel.app/guides/sheetmanager
Open a registered ActionSheet from anywhere in your application by calling SheetManager.show() with the sheet's registered name.
```javascript
SheetManager.show('example-sheet');
```
--------------------------------
### Snap to Offset
Source: https://rnas.vercel.app/reference/actionsheetref
Snap the action sheet to a specific offset percentage. The offset must be a number between 0 and 100.
```typescript
ref.current?.snapToOffset(20);
```
--------------------------------
### Integrating LegendList with ActionSheet
Source: https://rnas.vercel.app/guides/legendlist
Import ActionSheet, ScrollView, and LegendList. Use LegendList within ActionSheet, specifying ScrollView as the renderScrollComponent.
```javascript
import ActionSheet, {ScrollView} from 'react-native-actions-sheet';
import {LegendList} from '@legendapp/list';
const ExampleSheet = () => {
return (
} />
);
};
```
--------------------------------
### Render ActionSheet with a Ref
Source: https://rnas.vercel.app/usage
Create an ActionSheet instance within your component and assign a ref to it for programmatic control. Ensure you have imported `useRef` from React.
```javascript
function App() {
const actionSheetRef = useRef(null);
return (
Hi, I am here.
);
}
```
--------------------------------
### Register ActionSheet with SheetRegister
Source: https://rnas.vercel.app/guides/sheetmanager
Create a sheets.tsx file to import your custom sheet and register it using SheetRegister. This step is crucial for making the sheet available to SheetManager. It also includes extending the Sheets interface for better type safety and intellisense.
```typescript
import {SheetRegister, SheetDefinition} from 'react-native-actions-sheet';
import ExampleSheet from 'example-sheet.tsx';
// We extend some of the types here to give us great intellisense
// across the app for all registered sheets.
declare module 'react-native-actions-sheet' {
interface Sheets {
'example-sheet': SheetDefinition;
}
}
export const Sheets = () => {
return
}
```
--------------------------------
### snapToIndex
Source: https://rnas.vercel.app/reference/actionsheetref
Snaps the action sheet to a specific index, useful when multiple snap points are configured.
```APIDOC
## `snapToIndex`
### Description
When multiple snap points are set on the action sheet, use this to snap it to different position.
### Method
Invoke
### Endpoint
ActionSheetRef.snapToIndex(index)
### Parameters
#### Path Parameters
- **index** (number) - Required - Snap to the snap point at given index.
### Code Example
```javascript
ref.current?.snapToIndex(1);
```
```
--------------------------------
### Registering an ActionSheet
Source: https://rnas.vercel.app/reference/registersheet
Register a sheet with a unique ID and its corresponding component. You can optionally specify contexts for rendering.
```javascript
registerSheet("example-sheet", ExampleSheet, "global", "local-context");
```
--------------------------------
### Create Reusable ActionSheet Component
Source: https://rnas.vercel.app/guides/sheetmanager
Define your ActionSheet component and export it for reuse. Ensure it's a valid React component.
```javascript
function ExampleSheet() {
return (
Hello World
);
}
export default ExampleSheet;
```
--------------------------------
### Enable Background Interaction
Source: https://rnas.vercel.app/guides/background
Enables background interaction for the ActionSheet, using a regular View instead of a Modal. This allows interaction with elements behind the ActionSheet.
```jsx
```
--------------------------------
### Chaining ActionSheets
Source: https://rnas.vercel.app/guides/getdata
Chain multiple ActionSheets sequentially using await. Each sheet's promise resolves when it is closed, allowing for conditional display of subsequent sheets.
```typescript
let result = await SheetManager.show('sheet-a');
if (result) return await SheetManager.show('sheet-b');
```
--------------------------------
### hide
Source: https://rnas.vercel.app/reference/actionsheetref
Hides the action sheet. Optionally accepts data to return to the caller.
```APIDOC
## `hide`
### Description
Hide the action sheet.
### Method
Invoke
### Endpoint
ActionSheetRef.hide([data])
### Parameters
#### Path Parameters
- **data** (any) - Required - The data to return to the caller.
### Code Example
```javascript
ref.current?.hide({confirmed: true});
```
```
--------------------------------
### Register Multiple Sheets
Source: https://rnas.vercel.app/reference/sheetregister
Use SheetRegister to define a collection of sheets with unique IDs. Import SheetRegister and your sheet components, then pass an object mapping sheet IDs to their respective components.
```typescript
import {SheetRegister} from 'react-native-actions-sheet';
import ExampleSheet from 'example-sheet.tsx';
export const Sheets = () => {
return ;
};
```
--------------------------------
### Import ActionSheet
Source: https://rnas.vercel.app/guides/sheetmanager
Import the ActionSheet component from the react-native-actions-sheet library.
```javascript
import ActionSheet from 'react-native-actions-sheet';
```
--------------------------------
### Registering Sheets with Multiple Contexts
Source: https://rnas.vercel.app/guides/migrate
The registerSheet function now accepts multiple context arguments, allowing a sheet with the same ID to be opened in different contexts.
```typescript
registerSheet('sheet-id', ExampleSheet, 'context-a', 'context-b');
```
--------------------------------
### SheetManager.show
Source: https://rnas.vercel.app/reference/sheetmanager
Shows an action sheet with the given ID and optional options. This method is asynchronous and resolves when the action sheet closes, potentially returning a result. Data can be sent to the action sheet via the `payload` in the options.
```APIDOC
## SheetManager.show
### Description
Shows the action sheet with the given id with the provided options. This method is async. It resolves when the action sheet closes. It can return a result from the action sheet if needed. You can also send some data to the action sheet.
### Method
`show(id: string, options?: ShowOptions)`
### Parameters
#### Path Parameters
- **id** (string) - Required - An id of the action sheet you want to show.
- **options** (ShowOptions) - Optional - Options for showing the action sheet.
### Request Example
```javascript
SheetManager.show('example-sheet');
const confirmed = await SheetManager.show('confirm-sheet');
const confirmed = await SheetManager.show('confirm-sheet', {
payload: {message: 'Do you want to open this link?'},
});
```
```
--------------------------------
### Control Keyboard Handler
Source: https://rnas.vercel.app/reference/actionsheetref
Enable or disable the action sheet's keyboard handler. Pass false to disable.
```typescript
ref.current?.keyboardHandler(false);
```
--------------------------------
### ActionSheet Container Styling
Source: https://rnas.vercel.app/reference/actionsheet
Style the main container of the ActionSheet. Note that `maxHeight`, `marginBottom`, and `paddingBottom` are used internally. For padding, add it to a child View.
```jsx
```
--------------------------------
### Show ActionSheet with Payload
Source: https://rnas.vercel.app/guides/passingdata
Pass data to the ActionSheet when showing it using `SheetManager.show`. The payload is automatically available as a prop within the ActionSheet component.
```javascript
SheetManager.show('example-sheet', {
payload: {value: 'Hello World'},
});
```
--------------------------------
### Hide Action Sheet with Data
Source: https://rnas.vercel.app/reference/actionsheetref
Hide the action sheet and optionally return data to the caller. The data parameter is of type 'any' and is required.
```typescript
ref.current?.hide({confirmed: true});
```
--------------------------------
### Register Sheets with SheetRegister Component
Source: https://rnas.vercel.app/guides/migrate
Use the new SheetRegister component to easily register multiple sheets in one place for v10.0.0.
```typescript
import {SheetRegister} from 'react-native-actions-sheet';
import ExampleSheet from 'example-sheet.tsx';
export const Sheets = () => {
return
}
```
--------------------------------
### Draw Under Status Bar
Source: https://rnas.vercel.app/guides/safearea
Set `drawUnderStatusBar` to true for full-screen action sheets to allow them to extend underneath the status bar.
```javascript
```
--------------------------------
### registerSheet
Source: https://rnas.vercel.app/reference/registersheet
Registers an ActionSheet component with the SheetProvider, making it available for display. It requires a unique ID and the sheet component itself, with an optional list of contexts for multi-provider scenarios.
```APIDOC
## registerSheet
### Description
A function used to register an `ActionSheet` with `SheetProvider`.
### Parameters
#### Parameters
- **id** (string) - Required - Id for the sheet. It should be something unique and human readable. For example, `confirm-sheet`.
- **Sheet** (React.ElementType) - Required - The component that contains the action sheet.
- **contexts** (...string[]) - Optional - If you have multiple `SheetProviders` in the app, you can provide a list of contexts where the action sheet can render.
### Example
```javascript
registerSheet("example-sheet", ExampleSheet, "global", "local-context");
```
### Notes
A `SheetProvider` without a `context` prop has "global" context by default. When you register a action sheet without any context, it's automatically registered with the "global" SheetProvider.
```
--------------------------------
### keyboardHandler
Source: https://rnas.vercel.app/reference/actionsheetref
Disables or enables the action sheet's keyboard handler.
```APIDOC
## `keyboardHandler`
### Description
Disable or enable sheet keyboard handler.
### Method
Invoke
### Endpoint
ActionSheetRef.keyboardHandler(enable)
### Parameters
#### Path Parameters
- **enable** (boolean) - Required - Whether to enable or disable the keyboard handler.
### Code Example
```javascript
ref.current?.keyboardHandler(false);
```
```
--------------------------------
### Updating SheetManager.show payload
Source: https://rnas.vercel.app/guides/migrate
The payload structure for SheetManager.show has changed. Data should now be passed within a 'payload' object.
```typescript
SheetManager.show('sheet-id', {
payload: {data: 'hello world'},
});
```
--------------------------------
### ConfirmSheet Component
Source: https://rnas.vercel.app/guides/getdata
Implement the ActionSheet component, handling user interactions to hide the sheet with a specific payload.
```typescript
function ConfirmSheet(props: SheetProps<"confirm-sheet">) {
return (
{props.payload?.message}
);
}
```
--------------------------------
### Import ScrollView and FlatList
Source: https://rnas.vercel.app/guides/scrolling
Import `ScrollView` and `FlatList` from `react-native-actions-sheet` to enable scrolling within an ActionSheet. This ensures gestures and scrolling work together correctly.
```javascript
import ActionSheet, {ScrollView, FlatList} from 'react-native-actions-sheet';
const ExampleSheet = () => {
return (
);
};
```
--------------------------------
### SheetManager.get
Source: https://rnas.vercel.app/reference/sheetmanager
Retrieves the internal reference for an action sheet, allowing direct invocation of methods defined in `ActionSheetRef`. A context can be provided if the sheet exists within a specific `SheetProvider`.
```APIDOC
## SheetManager.get
### Description
Gives you the internal `ref` for the action sheet which can then be used to invoke methods in `ActionSheetRef`. If the action sheet you want to get exists in a specific `SheetProvider`, pass it's context along to get the correct `ref`.
### Method
`get(id: string, context?: string)`
### Parameters
#### Path Parameters
- **id** (string) - Required - An id of the action sheet you want to hide.
- **context** (string) - Optional - The context of the `SheetProvider` if the action sheet is scoped.
### Request Example
```javascript
SheetManager.get('example-sheet')?.snapToOffset(25);
// or inside some modal with it's own `SheetProvider`
SheetManager.get('example-sheet', 'local-context')?.snapToOffset(25);
```
```
--------------------------------
### Define Return Value Types
Source: https://rnas.vercel.app/guides/getdata
Define the payload and return value types for your sheet using TypeScript. This ensures type safety when interacting with the sheet.
```typescript
import {SheetDefinition, registerSheet} from 'react-native-actions-sheet';
registerSheet("confirm-sheet", ExampleSheet);
declare module 'react-native-actions-sheet' {
interface Sheets {
'confirm-sheet': SheetDefinition<{
payload: {
message: string
}
returnValue: boolean;
}>;
}
}
```
--------------------------------
### Scrolling with Other Scrollable Components
Source: https://rnas.vercel.app/guides/scrolling
Use the `useScrollHandlers` hook and `NativeViewGestureHandler` to enable scrolling for components like WebView or DatePicker inside an ActionSheet. This allows for proper gesture handling alongside the native scrolling behavior.
```javascript
import {ScrollView} from 'react-native';
import ActionSheet, {useScrollHandlers} from 'react-native-actions-sheet';
import {NativeViewGestureHandler} from 'react-native-gesture-handler';
const Sheet = () => {
const handlers = useScrollHandlers();
return (
);
};
```
--------------------------------
### Updating SheetManager.hide payload
Source: https://rnas.vercel.app/guides/migrate
Similar to show, the payload for SheetManager.hide now requires data to be nested within a 'payload' object.
```typescript
SheetManager.hide('sheet-id', {
payload: {data: 'hello world'},
});
```
--------------------------------
### currentPayload
Source: https://rnas.vercel.app/reference/actionsheetref
Retrieves the current payload associated with the action sheet.
```APIDOC
## `currentPayload`
### Description
Get the current payload for this action sheet.
### Method
Get
### Endpoint
ActionSheetRef.currentPayload()
```
--------------------------------
### SheetManager.hideAll
Source: https://rnas.vercel.app/reference/sheetmanager
Hides all currently opened action sheets.
```APIDOC
## SheetManager.hideAll
### Description
Hide all the action sheets that are currently opened.
### Method
`hideAll()`
### Request Example
```javascript
SheetManager.hideAll();
```
```
--------------------------------
### Android Styles XML for Transparent Navigation Bar
Source: https://rnas.vercel.app/guides/navigationbar
Configure the default navigation bar color to transparent in your Android app's `styles.xml` file. This is a prerequisite for using dynamic navigation bar color changes.
```xml
```
--------------------------------
### Hide All Action Sheets
Source: https://rnas.vercel.app/reference/sheetmanager
Closes all currently open action sheets globally.
```javascript
SheetManager.hideAll();
```
--------------------------------
### Hide Action Sheet and Return Data
Source: https://rnas.vercel.app/reference/sheetmanager
Hides an action sheet and passes data back to the function that initially called `SheetManager.show`.
```javascript
SheetManager.hide('example-sheet', {
payload: {confirmed: true},
});
```
--------------------------------
### SheetManager.getActiveSheets
Source: https://rnas.vercel.app/reference/sheetmanager
Retrieves all active instances of a sheet for a given sheet ID. This allows iteration over active sheets to perform actions on them.
```APIDOC
## SheetManager.getActiveSheets
### Description
Get all active sheets for a given sheet id. This allows you to iterate over active sheets and perform actions on them.
### Method
`getActiveSheets(id: string)`
### Parameters
#### Path Parameters
- **id** (string) - Required - An id of the action sheet.
### Request Example
```javascript
const activeSheets = SheetManager.getActiveSheets('example-sheet');
for (const sheet of activeSheets) {
if (sheet.ref.current.currentPayload().id === 'custom-id') {
sheet.ref.current.hide();
}
}
```
```
--------------------------------
### Migrating ScrollView to useScrollHandlers
Source: https://rnas.vercel.app/guides/migrate
Replace the manual attachment of handleChildScrollEnd with the useScrollHandlers hook for managing ScrollView behavior within ActionSheet.
```typescript
const actionSheetRef = useRef(null);
const scrollHandlers = useScrollHandlers('scroll-1', actionSheetRef);
return (
;
);
```
--------------------------------
### Basic ScrollView Integration with useScrollHandlers
Source: https://rnas.vercel.app/reference/usescrollhandlers
Integrates a React Native ScrollView with the action sheet using the useScrollHandlers hook. Ensure the ScrollView implements onScroll and onLayout props. The hook manages scrolling behavior based on the ScrollView's layout and position.
```javascript
import {ScrollView} from 'react-native';
import ActionSheet, {useScrollHandlers} from 'react-native-actions-sheet';
import {NativeViewGestureHandler} from 'react-native-gesture-handler';
const ExampleSheet = () => {
const handlers = useScrollHandlers();
return (
);
};
```
--------------------------------
### SheetManager.hide
Source: https://rnas.vercel.app/reference/sheetmanager
Hides an action sheet with the specified ID. An optional `data` parameter can be provided to return information to the caller.
```APIDOC
## SheetManager.hide
### Description
Hide the action sheet with the given id. The hide function takes an optional `data` parameter which can be used to return some data to the caller.
### Method
`hide(id: string, options?: HideOptions)`
### Parameters
#### Path Parameters
- **id** (string) - Required - An id of the action sheet you want to hide.
- **options** (HideOptions) - Optional - Options for hiding the action sheet.
### Request Example
```javascript
SheetManager.hide('example-sheet');
SheetManager.hide('example-sheet', {
payload: {confirmed: true},
});
```
```
--------------------------------
### Access ActionSheetRef in a specific SheetProvider
Source: https://rnas.vercel.app/guides/refaccess
Retrieve an action sheet reference within a specific SheetProvider context by providing both the sheet ID and the context name. This helps manage multiple instances of sheets.
```typescript
SheetManager.get('example-sheet', 'local-context').snapToOffset(50);
```
--------------------------------
### Define Sheet Payload Data
Source: https://rnas.vercel.app/guides/passingdata
Define the payload data structure for your ActionSheet when registering it. This uses TypeScript module augmentation to specify the expected payload shape.
```typescript
import {SheetDefinition} from 'react-native-actions-sheet';
declare module 'react-native-actions-sheet' {
interface Sheets {
'example-sheet': SheetDefinition<{
payload: {
value: string;
};
}>;
}
}
```
--------------------------------
### Update an Action Sheet
Source: https://rnas.vercel.app/reference/sheetmanager
Updates an active action sheet by modifying its payload or overriding its props. Requires the sheet's ID and new options.
```javascript
SheetManager.update('payload', {
payload: {
candy: 'Chocolate',
},
});
```
--------------------------------
### Disable Closing with Background Interaction
Source: https://rnas.vercel.app/guides/background
Enables background interaction and prevents the ActionSheet from closing via gestures or other interactions. Useful for persistent UI elements.
```jsx
```
--------------------------------
### isGestureEnabled
Source: https://rnas.vercel.app/reference/actionsheetref
Checks if gestures are currently enabled or disabled for the action sheet.
```APIDOC
## `isGestureEnabled`
### Description
Check if the action sheet has gestures enabled or disabled.
### Method
Get
### Endpoint
ActionSheetRef.isGestureEnabled()
```
--------------------------------
### SheetManager.update
Source: https://rnas.vercel.app/reference/sheetmanager
Updates an active action sheet by providing new payload data or overriding its properties.
```APIDOC
## SheetManager.update
### Description
Update an active ActionSheet with new payload or override it's props.
### Method
`update(id: string, options: UpdateOptions)`
### Parameters
#### Path Parameters
- **id** (string) - Required - An id of the action sheet.
- **options** (UpdateOptions) - Required - Options to update the action sheet.
### Request Example
```javascript
SheetManager.update('payload', {
payload: {
candy: 'Chocolate',
},
});
```
```
--------------------------------
### Hide ActionSheet Programmatically
Source: https://rnas.vercel.app/usage
Dismiss the ActionSheet from the screen by calling the `hide` method on its ref. This is used to close the sheet after an action is completed.
```javascript
actionSheetRef.current?.hide();
```
--------------------------------
### Hide ActionSheet using SheetManager
Source: https://rnas.vercel.app/guides/sheetmanager
Close a currently displayed ActionSheet by calling SheetManager.hide() with the sheet's registered name.
```javascript
SheetManager.hide('example-sheet');
```