1 | # react-native-action-sheet [![Slack](https://slack.expo.io/badge.svg)](https://slack.expo.io)
|
2 |
|
3 | 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.
|
4 |
|
5 | ## Installation
|
6 |
|
7 | ```
|
8 | npm install @expo/react-native-action-sheet -S
|
9 | ```
|
10 | or
|
11 | ```
|
12 | yarn add @expo/react-native-action-sheet
|
13 | ```
|
14 |
|
15 | ## A basic ActionSheet Setup
|
16 |
|
17 | ### 1. import connectActionSheet function and connect your component which uses showActionSheetWithOptions.
|
18 | ```es6
|
19 | import { connectActionSheet } from '@expo/react-native-action-sheet';
|
20 |
|
21 | class App extends React.Component {
|
22 | /* ... */
|
23 | }
|
24 |
|
25 | const ConnectedApp = connectActionSheet(App)
|
26 |
|
27 | export default ConnectedApp
|
28 | ```
|
29 |
|
30 | `App` component can access actionSheet method as `this.props.showActionSheetWithOptions`
|
31 |
|
32 | ```es6
|
33 | _onOpenActionSheet = () => {
|
34 | // Same interface as https://facebook.github.io/react-native/docs/actionsheetios.html
|
35 | const options = ['Delete', 'Save', 'Cancel'];
|
36 | const destructiveButtonIndex = 0;
|
37 | const cancelButtonIndex = 2;
|
38 |
|
39 | this.props.showActionSheetWithOptions(
|
40 | {
|
41 | options,
|
42 | cancelButtonIndex,
|
43 | destructiveButtonIndex,
|
44 | },
|
45 | buttonIndex => {
|
46 | // Do something here depending on the button index selected
|
47 | },
|
48 | );
|
49 | };
|
50 | ```
|
51 |
|
52 | ### 2. import ActionSheetProvider and wrap your top-level component with `<ActionSheetProvider />`
|
53 |
|
54 | ```es6
|
55 |
|
56 | import { ActionSheetProvider } from '@expo/react-native-action-sheet';
|
57 | class AppContainer extends React.Component {
|
58 | render() {
|
59 | return (
|
60 | <ActionSheetProvider>
|
61 | <ConnectedApp />
|
62 | </ActionSheetProvider>
|
63 | );
|
64 | }
|
65 | }
|
66 | ```
|
67 |
|
68 | ## Web Setup
|
69 | WIP
|
70 |
|
71 | ## Options
|
72 |
|
73 | The goal of this library is to mimic the native iOS and Android ActionSheets as closely as possible.
|
74 |
|
75 | This library can also be used with on web with Expo.
|
76 |
|
77 | ### Universal Props
|
78 |
|
79 | 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.
|
80 |
|
81 | ### Android/Web-Only Props
|
82 |
|
83 | 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.
|
84 |
|
85 |
|
86 | | Name | Type | Required | Default |
|
87 | | -----------------| ----------------------------------| -------- | ------- |
|
88 | | icons | array of required images or icons | No | |
|
89 | | tintIcons | boolean | No | true |
|
90 | | textStyle | TextStyle | No | |
|
91 | | titleTextStyle | TextStyle | No | |
|
92 | | messageTextStyle | TextStyle | No | |
|
93 | | showSeparators | boolean | No | false |
|
94 | | separatorStyle | ViewStyle | No | |
|
95 |
|
96 | #### `icons` (optional)
|
97 |
|
98 | 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.
|
99 |
|
100 | #### `tintIcons` (optional)
|
101 | 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.
|
102 |
|
103 | #### `textStyle` (optional)
|
104 | Apply any text style props to the options. If the `tintColor` option is provided, it takes precedence over a color text style prop.
|
105 |
|
106 | #### `titleTextStyle` (optional)
|
107 | Apply any text style props to the title if present.
|
108 |
|
109 | #### `messageTextStyle` (optional)
|
110 | Apply any text style props to the message if present.
|
111 |
|
112 | #### `showSeparators`: (optional)
|
113 | Show separators between items. On iOS, separators always show so this prop has no effect.
|
114 |
|
115 | #### `separatorStyle`: (optional)
|
116 | Modify the look of the separators rather than use the default look.
|
117 |
|
118 | ## Try it out
|
119 |
|
120 | Try it in Expo: https://expo.io/@community/react-native-action-sheet-example
|
121 |
|
122 | ## Example
|
123 |
|
124 | See the [example app](https://github.com/expo/react-native-action-sheet/tree/master/example) for examples of how to apply different options.
|
125 |
|
126 | ### Usage
|
127 | ```
|
128 | $ cd exmaple
|
129 | $ yarn
|
130 | $ yarn ios
|
131 | ``` |
\ | No newline at end of file |