A highly customizable cross platform ActionSheet for react native.
- Cross Platform (iOS and Android)
- Native Animations & Performance
- Identical Working on Android and iOS
- Control ActionSheet with Gestures
- Raw ActionSheet - You can Add Anything
- Allow ActionSheet to be partially shown when opened
- Support TextInputs
- Cool bounce effect on open.
- Support for Tablets and iPads
- Support Horizontal Layout
- Support for Nested Scrolling or Scrollable Content.
- Virtualization Support
git clone https://github.com/ammarahm-ed/react-native-actions-sheet.git
then run yarn or npm install
in the example folder and finally to run the example app:
react-native run-android
npm install react-native-actions-sheet --save
or if you use yarn:
yarn add react-native-actions-sheet
import ActionSheet from "react-native-actions-sheet";
import React, { createRef } from "react";
const actionSheetRef = createRef();
const App = () => {
let actionSheet;
return (
<View
style={{
justifyContent: "center",
flex: 1,
}}
>
<TouchableOpacity
onPress={() => {
actionSheetRef.current?.setModalVisible();
}}
>
<Text>Open ActionSheet</Text>
</TouchableOpacity>
<ActionSheet ref={actionSheetRef}>
<View>
<Text>YOUR CUSTOM COMPONENT INSIDE THE ACTIONSHEET</Text>
</View>
</ActionSheet>
</View>
);
};
export default App;
Assigns a ref to ActionSheet component to use methods.
Type | Required |
---|---|
ref | Yes |
Use if you want to show the ActionSheet Partially on Opening. Requires gestureEnabled=true
Type | Required |
---|---|
boolean | 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
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.Component | no |
Keep the header always visible even when gestures are disabled.
Type | Required |
---|---|
boolean | no |
Default: false
A footer component if you want to add some info at the bottom.
Type | Required |
---|---|
React.Component | no |
Note: Remember to give footer a fixed height and provide ActionSheet the footerHeight
prop with same value. If you have added margins etc, add those values to footerHeight
also.
Height of the footer
Type | Required |
---|---|
number | no |
Default: 80
Custom Styles for the footer container.
Type | Required |
---|---|
Object | no |
Keep footer visible. Currently when you overdraw, the footer appears, however you can change this by setting this to true
.
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.
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 to bottomOffset
location
Type | Required |
---|---|
boolean | no |
Default: true
Snap ActionSheet to this location if closable
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 the ScrollView
component. Should be one of "never", "always" or "handled"
Type | Required |
---|---|
string | no |
Default: never
Determine whether the modal should go under the system statusbar.
Type | Required |
---|---|
boolean | no |
Default: true
Will the ActionSheet close on hardwareBackPress
event.
Type | Required |
---|---|
boolean | no |
Default: true
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.
ActionSheet can be opened or closed using its ref.
import ActionSheet from "react-native-actions-sheet";
import React, { createRef } from "react";
const actionSheetRef = createRef();
// First create a ref on your <ActionSheet/> Component.
<ActionSheet ref={actionSheetRef} />;
// then later in your function to open the ActionSheet:
actionSheetRef.current?.setModalVisible();
It's also possible to explicitly either show or hide modal.
import ActionSheet from "react-native-actions-sheet";
import React, { createRef } from "react";
const actionSheetRef = createRef();
// First create a ref on your <ActionSheet/> Component.
<ActionSheet ref={actionSheetRef} />;
// then to show modal use
actionSheetRef.current?.setModalVisible(true);
// and later you may want to hide it using
actionSheetRef.current?.setModalVisible(false);
When the ActionSheet is open, you can progammatically snap it to different offsets.
import ActionSheet from "react-native-actions-sheet";
import React, { createRef } from "react";
const actionSheetRef = createRef();
// First create a ref on your <ActionSheet/> Component.
<ActionSheet ref={actionSheetRef} />;
// snap to this location on screen
actionSheetRef.current?.snapToOffset(200);
actionSheetRef.current?.snapToOffset(150);
actionSheetRef.current?.snapToOffset(300);
Listen to changes in ActionSheet State.
Attach a listener to know when ActionSheet is fully opened and has reached top. Use this if you want to use a ScrollView inside the ActionSheet. Check the example for demonstration on how to use nested ScrollViews inside ActionSheet.
import ActionSheet, {addHasReachedTopListener, removeHasReachedTopListener} from 'react-native-actions-sheet
// In your Component
const _onHasReachedTop = (hasReached) => {
// handle the event
}
useEffect(() => {
addHasReachedTopListener(_onHasReachedTop)
return () => {
removeHasReachedTopListener(_onHasReachedTop)
}
},[])
Support it by donating or joining stargazers for this repository. ⭐️ and follow me for my next creations!