### 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 (