1 | # react-native-action-sheet
|
2 | [![npm](https://img.shields.io/npm/v/@expo/react-native-action-sheet.svg?style=flat-square)](https://www.npmjs.com/package/@expo/react-native-action-sheet)
|
3 | [![License: MIT](https://img.shields.io/github/license/nd-02110114/goofi-mobile.svg)](https://opensource.org/licenses/MIT)
|
4 | [![Slack](https://slack.expo.io/badge.svg)](https://slack.expo.io)
|
5 |
|
6 | ActionSheet is a cross-platform React Native component that uses the native UIActionSheet on iOS and a JS implementation on Android. Almost a drop in replacement for [ActionSheetIOS](https://facebook.github.io/react-native/docs/actionsheetios.html) except it cannot be called statically.
|
7 |
|
8 |
|
9 | | iOS | Android | Web |
|
10 | |---------------------------|---------------------------|---------------------------|
|
11 | | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/ios.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/android.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/web.gif" width="400" height="400"/> |
|
12 |
|
13 |
|
14 | ## Installation
|
15 |
|
16 | ```
|
17 | $ npm install @expo/react-native-action-sheet -S
|
18 | ```
|
19 | or
|
20 | ```
|
21 | $ yarn add @expo/react-native-action-sheet
|
22 | ```
|
23 |
|
24 | ## A basic ActionSheet Setup
|
25 |
|
26 | ### 1. Wrap your top-level component with `<ActionSheetProvider />`
|
27 |
|
28 | ```es6
|
29 |
|
30 | import { ActionSheetProvider } from '@expo/react-native-action-sheet'
|
31 |
|
32 | class AppContainer extends React.Component {
|
33 | render() {
|
34 | return (
|
35 | <ActionSheetProvider>
|
36 | <ConnectedApp />
|
37 | </ActionSheetProvider>
|
38 | );
|
39 | }
|
40 | }
|
41 | ```
|
42 |
|
43 | ### 2. Connect your component which uses showActionSheetWithOptions.
|
44 | ```es6
|
45 | import { connectActionSheet } from '@expo/react-native-action-sheet'
|
46 |
|
47 | class App extends React.Component {
|
48 | /* ... */
|
49 | }
|
50 |
|
51 | const ConnectedApp = connectActionSheet(App)
|
52 |
|
53 | export default ConnectedApp
|
54 | ```
|
55 |
|
56 | `App` component can access the actionSheet method as `this.props.showActionSheetWithOptions`
|
57 |
|
58 | ```es6
|
59 | _onOpenActionSheet = () => {
|
60 | // Same interface as https://facebook.github.io/react-native/docs/actionsheetios.html
|
61 | const options = ['Delete', 'Save', 'Cancel'];
|
62 | const destructiveButtonIndex = 0;
|
63 | const cancelButtonIndex = 2;
|
64 |
|
65 | this.props.showActionSheetWithOptions(
|
66 | {
|
67 | options,
|
68 | cancelButtonIndex,
|
69 | destructiveButtonIndex,
|
70 | },
|
71 | buttonIndex => {
|
72 | // Do something here depending on the button index selected
|
73 | },
|
74 | );
|
75 | };
|
76 | ```
|
77 |
|
78 | You can use a hook instead of the higher order component if you are on React 16.8 or newer.
|
79 |
|
80 | ```es6
|
81 | import { useActionSheet } from '@expo/react-native-action-sheet'
|
82 |
|
83 | export default function App () {
|
84 | const { showActionSheetWithOptions } = useActionSheet();
|
85 | /* ... */
|
86 | }
|
87 | ```
|
88 |
|
89 | ## Options
|
90 |
|
91 | The goal of this library is to mimic the native iOS and Android ActionSheets as closely as possible.
|
92 |
|
93 | This library can also be used in the browser with Expo for web.
|
94 |
|
95 | ### Universal Props
|
96 |
|
97 | The same options available on React Native's [ActionSheetIOS](https://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions) component exist for both iOS and Android in this library.
|
98 |
|
99 | ### iOS Only Props
|
100 |
|
101 | | Name | Type | Required | Default |
|
102 | | -------------------| -------| -------- | ------- |
|
103 | | anchor | number | No | |
|
104 | | userInterfaceStyle | string | No | |
|
105 |
|
106 | #### `anchor` (optional)
|
107 | iPad only option that allows for docking the action sheet to a node. See [ShowActionSheetButton.tsx](/example/ShowActionSheetButton.tsx) for an example on how to implement this.
|
108 |
|
109 | #### `userInterfaceStyle` (optional)
|
110 | The interface style used for the action sheet, can be set to `light` or `dark`, otherwise the default system style will be used.
|
111 |
|
112 | ### Android/Web-Only Props
|
113 |
|
114 | The below props allow modification of the Android ActionSheet. They have no effect on the look on iOS as the native iOS Action Sheet does not have options for modifying these options.
|
115 |
|
116 |
|
117 | | Name | Type | Required | Default |
|
118 | | -----------------| ----------------------------------| -------- | ------- |
|
119 | | icons | array of required images or icons | No | |
|
120 | | tintIcons | boolean | No | true |
|
121 | | textStyle | TextStyle | No | |
|
122 | | titleTextStyle | TextStyle | No | |
|
123 | | messageTextStyle | TextStyle | No | |
|
124 | | autoFocus | boolean | No | false |
|
125 | | showSeparators | boolean | No | false |
|
126 | | containerStyle | ViewStyle | No | |
|
127 | | separatorStyle | ViewStyle | No | |
|
128 | | useModal | boolean | No | false |
|
129 | | destructiveColor | string | No | #d32f2f |
|
130 |
|
131 | #### `icons` (optional)
|
132 |
|
133 | Show icons to go along with each option. If image source paths are provided via `require`, images will be rendered for you. Alternatively, you can provide an array of elements such as vector icons, pre-rendered Images, etc.
|
134 |
|
135 | #### `tintIcons` (optional)
|
136 | Icons by default will be tinted to match the text color. When set to false, the icons will be the color of the source image. This is useful if you want to use multicolor icons. If you provide your own nodes/pre-rendered icons rather than required images in the `icons` array, you will need to tint them appropriately before providing them in the array of `icons`; `tintColor` will not be applied to icons unless they are images from a required source.
|
137 |
|
138 | #### `textStyle` (optional)
|
139 | Apply any text style props to the options. If the `tintColor` option is provided, it takes precedence over a color text style prop.
|
140 |
|
141 | #### `titleTextStyle` (optional)
|
142 | Apply any text style props to the title if present.
|
143 |
|
144 | #### `messageTextStyle` (optional)
|
145 | Apply any text style props to the message if present.
|
146 |
|
147 | #### `autoFocus`: (optional)
|
148 | If true, will give the first option screen reader focus automatically when the action sheet becomes visible.
|
149 | On iOS, this is the default behavior of the native action sheet.
|
150 |
|
151 | #### `showSeparators`: (optional)
|
152 | Show separators between items. On iOS, separators always show so this prop has no effect.
|
153 |
|
154 | #### `containerStyle`: (optional)
|
155 | Apply any view style props to the container rather than use the default look (e.g. dark mode).
|
156 |
|
157 | #### `separatorStyle`: (optional)
|
158 | Modify the look of the separators rather than use the default look.
|
159 |
|
160 | #### `useModal`: (optional)
|
161 | Wrap the ActionSheet with a Modal, in order to show in front of other Modals that were already opened ([issue reference](https://github.com/expo/react-native-action-sheet/issues/164)).
|
162 |
|
163 | #### `destructiveColor`: (optional)
|
164 | Modify color for text of destructive option.
|
165 |
|
166 | ## ActionSheetProvider Props
|
167 |
|
168 | The following props can be set directly on the `ActionSheetProvider`
|
169 |
|
170 | #### `useNativeDriver` (optional)
|
171 | Windows only option that provides the option to disable the [native animation](https://reactnative.dev/docs/animated#using-the-native-driver) driver for React Native Windows projects targeting _Windows 10 Version-1809 ; Build-10.0.17763.0_ and earlier. `useNativeDriver` is [supported in Version-1903 and later](https://microsoft.github.io/react-native-windows/docs/win10-compat) so if your project is targeting that, you don't need to set this prop.
|
172 |
|
173 |
|
174 | ## Try it out
|
175 |
|
176 | Try it in Expo: https://expo.io/@community/react-native-action-sheet-example
|
177 |
|
178 | ## Example
|
179 |
|
180 | See the [example app](https://github.com/expo/react-native-action-sheet/tree/master/example).
|
181 |
|
182 | ### Usage
|
183 | ```
|
184 | $ cd example
|
185 | $ yarn
|
186 |
|
187 | // build simulator
|
188 | $ yarn ios
|
189 | $ yarn android
|
190 |
|
191 | // web
|
192 | $ yarn web
|
193 | ```
|
194 |
|
195 | ## Development
|
196 |
|
197 | ### Setup
|
198 | ```
|
199 | $ git clone git@github.com:expo/react-native-action-sheet.git
|
200 | $ cd react-native-action-sheet
|
201 | $ yarn
|
202 | ```
|
203 |
|
204 | ### Build
|
205 | We use [bob](https://github.com/react-native-community/bob).
|
206 | ```
|
207 | $ yarn build
|
208 | ```
|
209 |
|
210 | ### Lint & Format
|
211 | ```
|
212 | // tsc
|
213 | $ yarn type-check
|
214 |
|
215 | // ESLint
|
216 | $ yarn lint
|
217 |
|
218 | // prettier
|
219 | $ yarn fmt
|
220 | ```
|