Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork147
A Cross Platform(Android, iOS & Web) ActionSheet with a flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.
License
ammarahm-ed/react-native-actions-sheet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
npm install react-native-actions-sheet --save
OR
yarn add react-native-actions-sheet
Create your ActionSheet component and register it with a unique id. Remember that you do not need to render the ActionSheet in any components.
importReactfrom"react";importActionSheet,{SheetManager,SheetProps,registerSheet,}from"react-native-actions-sheet";functionMySheet(props:SheetProps){return(<ActionSheetid={props.sheetId}><View><Text>Hello World</Text></View></ActionSheet>);}// Register your Sheet component.registerSheet("mysheet",MySheet);exportdefaultMySheet;
Create asheets.tsx
orsheets.js
file.
// Import all the sheets here as followsimport"mysheet.tsx";export{};
InApp.js
importsheets.tsx
and wrap your app inSheetProvider
.
import{SheetProvider}from"react-native-actions-sheet";import"sheets.tsx";// herefunctionApp(){return(<SheetProvider>{// your app components}</SheetProvider>);}
Now you can open the ActionSheet from anywhere in the app.
SheetManager.show("mysheet");
Want to pass some data on opening the sheet or update the state?
SheetManager.show("mysheet",{value:"data"});<ActionSheetonBeforeShow={(data)=>{setData(data);}}id="helloworld_sheet">
Hiding the sheet is easy. Enable gestures or do the following.
awaitSheetManager.hide("mysheet");
Close all opened ActionSheets
SheetManager.hideAll();
You can also show the sheet without SheetProvider.
<ActionSheetid="mysheet"><View><Text>Hello World</Text></View></ActionSheet>
And then show it;
SheetManager.show("mysheet");
- Cross Platform (iOS and Android)
- Native Animations & Performance
- Identical Working on Android and iOS
- Control ActionSheet withGestures
- Raw ActionSheet - You can Add Anything
- Allow ActionSheet to be partially shown when opened
- Support TextInputs
- Coolbounce effect on open.
- Tablets and iPads
- Horizontal Layout
- Nested Scrolling or Scrollable Content.
- Virtualization Support
- Global Sheet Manager
- Proper resizing on Android & iOS on Keyboard show/hide.
Consider supporting with a ⭐️star on GitHub
If you are using the library in one of your projects, consider supporting with a star. It takes a lot of time and effort to keep this maintained and address issues and bugs. Thank you.
A unique id for the ActionSheet. You must set this if you are usingSheetManager
.
Type | Required |
---|---|
id | false |
Assigns a ref to ActionSheet component to use methods.
Type | Required |
---|---|
ref | false |
Test ID for unit testing
Type | Required |
---|---|
string | no |
Set this to false to use a simple View instead of a Modal to show the ActionSheet.
Type | Required |
---|---|
boolean | no |
default:true
Use if you want to show the ActionSheet Partially on Opening. **RequiresgestureEnabled=true
**
Type | Required |
---|---|
number | no |
Default:1
Normally when the ActionSheet is fully opened, a small portion from the bottom is hidden by default. Use this prop if you want the ActionSheet to hover over the bottom of screen and not hide a little behind it.
Type | Required |
---|---|
number | no |
Default:0
Style the top indicator bar in ActionSheet.
Type | Required |
---|---|
ViewStyle | no |
Any custom styles for the container.
Type | Required |
---|---|
Object | no |
Delay draw of ActionSheet on open for android.
Type | Required |
---|---|
boolean | no |
Default:false
Delay draw of ActionSheet on open for android time.
Type | Required |
---|---|
number (ms) | no |
Default:50
Your custom header component. Using this will hide the default indicator.
Type | Required |
---|---|
React. ReactNode | no |
Render a component over the ActionSheet. Useful for rendering Toast components with which user can interact.
Type | Required |
---|---|
React. ReactNode | no |
Keep the header always visible even when gestures are disabled.
Type | Required |
---|---|
boolean | no |
Default:false
Animate the opening and closing of ActionSheet.
Type | Required |
---|---|
boolean | no |
Default:true
Speed of opening animation. Higher means the ActionSheet will open more quickly. Use it in combination withbounciness
prop to have optimize the bounce/spring effect on ActionSheet open.
Type | Required |
---|---|
number | no |
Default:12
Duration of closing animation.
Type | Required |
---|---|
number | no |
Default:300
Enables gesture control of ActionSheet
Type | Required |
---|---|
boolean | no |
Default:false
Control closing ActionSheet by touching on backdrop.
Type | Required |
---|---|
boolean | no |
Default:true
Bounces the ActionSheet on open.
Type | Required |
---|---|
boolean | no |
Default:false
How much you want the ActionSheet to bounce when it is opened.
Type | Required |
---|---|
number | no |
Default:8
When touch ends and user has not moved farther from the set springOffset, the ActionSheet will return to previous position.
Type | Required |
---|---|
number | no |
Default:50
Add elevation to the ActionSheet container.
Type | Required |
---|---|
number | no |
Default:0
Color of the gestureEnabled Indicator.
Type | Required |
---|---|
string | no |
Default:"#f0f0f0"
Color of the overlay/backdrop.
Type | Required |
---|---|
string | no |
Default:"black"
Default opacity of the overlay/backdrop.
Type | Required |
---|---|
number 0 - 1 | no |
Default:0.3
Prevent ActionSheet from closing on gesture or tapping on backdrop. Instead snap it tobottomOffset
location
Type | Required |
---|---|
boolean | no |
Default:true
Snap ActionSheet to this location ifclosable
is set to false. By default it will snap to the location on first open.
Type | Required |
---|---|
number | no |
Default:0
Setting the keyboard persistence of theScrollView
component. Should be one of "never", "always" or "handled"
Type | Required |
---|---|
string | no |
Default:never
Allow to choose will content change position when keyboard is visible.This is enabled by default.
Type | Required |
---|---|
boolean | no |
Default:true
Set how keyboard should behave on tapping the ActionSheet.
Type | Required |
---|---|
"on-drag" "none" "interactive" | no |
Default :"none"
Determine whether the modal should go under the system statusbar.
Type | Required |
---|---|
boolean | no |
Default:true
Will the ActionSheet close onhardwareBackPress
event.
Type | Required |
---|---|
boolean | no |
Default:true
Allow ActionSheet to draw under the StatusBar. This is enabled by default.
Type | Required |
---|---|
boolean | no |
Default:false
Event called when position of ActionSheet changes.
Type | Required |
---|---|
function | no |
Event called when the ActionSheet closes.
Type | Required |
---|---|
function | no |
An event called when the ActionSheet Opens.
Type | Required |
---|---|
function | no |
Methods require you to set a ref on ActionSheet Component.
If your component includes any child ScrollView/FlatList you must attach this method to all scroll end callbacks.
<ScrollViewref={scrollViewRef}nestedScrollEnabled={true}onMomentumScrollEnd={()=>actionSheetRef.current?.handleChildScrollEnd()}.....
Opens the ActionSheet.
importActionSheetfrom"react-native-actions-sheet";importReact,{createRef}from"react";constactionSheetRef=createRef();// First create a ref on your <ActionSheet/> Component.<ActionSheetref={actionSheetRef}/>;// then later in your function to open the ActionSheet:actionSheetRef.current?.show();
Closes the ActionSheet.
importActionSheetfrom"react-native-actions-sheet";importReact,{createRef}from"react";constactionSheetRef=createRef();// First create a ref on your <ActionSheet/> Component.<ActionSheetref={actionSheetRef}/>;// then later in your function to open the ActionSheet:actionSheetRef.current?.hide();
ActionSheet can be opened or closed using its ref.
importActionSheetfrom"react-native-actions-sheet";importReact,{createRef}from"react";constactionSheetRef=createRef();// First create a ref on your <ActionSheet/> Component.<ActionSheetref={actionSheetRef}/>;// then later in your function to open the ActionSheet:actionSheetRef.current?.setModalVisible();
It's also possible to explicitly either show or hide modal.
importActionSheetfrom"react-native-actions-sheet";importReact,{createRef}from"react";constactionSheetRef=createRef();// First create a ref on your <ActionSheet/> Component.<ActionSheetref={actionSheetRef}/>;// then to show modal useactionSheetRef.current?.setModalVisible(true);// and later you may want to hide it usingactionSheetRef.current?.setModalVisible(false);
When the ActionSheet is open, you can progammatically snap it to different offsets.
importActionSheetfrom"react-native-actions-sheet";importReact,{createRef}from"react";constactionSheetRef=createRef();// First create a ref on your <ActionSheet/> Component.<ActionSheetref={actionSheetRef}/>;// snap to this location on screenactionSheetRef.current?.snapToOffset(200);actionSheetRef.current?.snapToOffset(150);actionSheetRef.current?.snapToOffset(300);
Nested scrolling on android is disabled by default. You can enable it as done below.
importActionSheetfrom"react-native-actions-sheet";constApp=()=>{constactionSheetRef=useRef();return(<ActionSheetref={actionSheetRef}><ScrollViewnestedScrollEnabled={true}onMomentumScrollEnd={()=>actionSheetRef.current?.handleChildScrollEnd()}/></ActionSheet>);};
Support it by donating or joining stargazers for this repository. ⭐️ and follow me for my next creations!
About
A Cross Platform(Android, iOS & Web) ActionSheet with a flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.