@@ -14,56 +14,32 @@ Cross platform ActionSheet. This component implements a custom ActionSheet and
14
14
</tbody >
15
15
</table >
16
16
17
- # Installation
17
+ ## Install
18
18
19
19
```
20
- npm i react-native-actionsheet --save
20
+ npm install react-native-actionsheet --save
21
21
```
22
22
23
23
## Usage
24
24
25
- ``` javascript
26
- import React from ' react'
27
- import { View , Text , StyleSheet , Modal , ListView } from ' react-native'
25
+ ``` js
28
26
import ActionSheet from ' react-native-actionsheet'
29
27
30
- const CANCEL_INDEX = 0
31
- const DESTRUCTIVE_INDEX = 4
32
- const options = [ ' Cancel' , ' Apple' , ' Banana' , ' Watermelon' , ' Durian' ]
33
- const title = ' Which one do you like?'
34
-
35
- class ExampleA extends React .Component {
36
- constructor (props ) {
37
- super (props)
38
- this .state = {
39
- selected: ' '
40
- }
41
- this .handlePress = this .handlePress .bind (this )
42
- this .showActionSheet = this .showActionSheet .bind (this )
43
- }
44
-
45
- showActionSheet () {
28
+ class Demo extends React .Component {
29
+ showActionSheet = () => {
46
30
this .ActionSheet .show ()
47
31
}
48
-
49
- handlePress (i ) {
50
- this .setState ({
51
- selected: i
52
- })
53
- }
54
-
55
32
render () {
56
33
return (
57
- < View style= {styles .wrapper }>
58
- < Text style= {{marginBottom: 20 }} > I like {options[this .state .selected ]}< / Text >
59
- < Text style= {styles .button } onPress= {this .showActionSheet }> Example A < / Text >
34
+ < View>
35
+ < Text onPress= {this .showActionSheet }> Open ActionSheet< / Text >
60
36
< ActionSheet
61
37
ref= {o => this .ActionSheet = o}
62
- title= {title }
63
- options= {options }
64
- cancelButtonIndex= {CANCEL_INDEX }
65
- destructiveButtonIndex= {DESTRUCTIVE_INDEX }
66
- onPress= {this . handlePress }
38
+ title= {' Which one do you like ? ' }
39
+ options= {[ ' Apple ' , ' Banana ' , ' cancel ' ] }
40
+ cancelButtonIndex= {2 }
41
+ destructiveButtonIndex= {1 }
42
+ onPress= {( index ) => { /* do something */ } }
67
43
/ >
68
44
< / View>
69
45
)
@@ -72,69 +48,70 @@ class ExampleA extends React.Component {
72
48
```
73
49
74
50
75
- ## Use ActionSheetCustom directly
51
+ ### Use ActionSheetCustom directly
76
52
77
53
so you can customize option and title
78
54
79
- ``` javascript
80
- import React from ' react'
81
- import { View , Text , StyleSheet , Modal , ListView } from ' react-native'
55
+ ``` js
82
56
import { ActionSheetCustom as ActionSheet } from ' react-native-actionsheet'
83
57
84
- const CANCEL_INDEX = 0
85
- const DESTRUCTIVE_INDEX = 4
86
-
87
- const options = [
58
+ const options = [
88
59
' Cancel' ,
89
60
' Apple' ,
90
61
< Text style= {{color: ' yellow' }}> Banana< / Text > ,
91
62
' Watermelon' ,
92
63
< Text style= {{color: ' red' }}> Durian< / Text >
93
64
]
94
65
95
- const title = < Text style= {{color: ' #000' , fontSize: 18 }}> Which one do you like? < / Text >
96
-
97
- class ExampleB extends React .Component {
98
- constructor (props ) {
99
- super (props)
100
- this .state = {
101
- selected: ' '
102
- }
103
- this .handlePress = this .handlePress .bind (this )
104
- this .showActionSheet = this .showActionSheet .bind (this )
105
- }
106
-
107
- showActionSheet () {
66
+ class Demo extends React .Component {
67
+ showActionSheet = () => {
108
68
this .ActionSheet .show ()
109
69
}
110
-
111
- handlePress (i ) {
112
- this .setState ({
113
- selected: i
114
- })
115
- }
116
-
117
70
render () {
118
71
return (
119
- < View style= {styles .wrapper }>
120
- < Text style= {{marginBottom: 20 }} > I like {options[this .state .selected ]}< / Text >
121
- < Text style= {styles .button } onPress= {this .showActionSheet }> Example B < / Text >
72
+ < View>
73
+ < Text onPress= {this .showActionSheet }> Open ActionSheet< / Text >
122
74
< ActionSheet
123
75
ref= {o => this .ActionSheet = o}
124
- title= {title }
76
+ title= {< Text style = {{color : ' #000 ' , fontSize : 18 }} > Which one do you like ? < / Text > }
125
77
options= {options}
126
- cancelButtonIndex= {CANCEL_INDEX }
127
- destructiveButtonIndex= {DESTRUCTIVE_INDEX }
128
- onPress= {this . handlePress }
78
+ cancelButtonIndex= {0 }
79
+ destructiveButtonIndex= {4 }
80
+ onPress= {( index ) => { /* do something */ } }
129
81
/ >
130
82
< / View>
131
83
)
132
84
}
133
85
}
134
86
` ` `
135
87
88
+ ### How to redesign style ?
89
+
90
+ The style of ActionSheet is defined in [lib/styles.js](https://github.com/beefe/react-native-actionsheet/blob/master/lib/styles.js). We can pass the ` styles` prop to cover default style. See [Example](https://github.com/beefe/react-native-actionsheet/blob/master/example/app/ExampleB.js#L48) .
91
+
92
+ ` ` ` javascript
93
+ // example
94
+
95
+ const styles = {
96
+ titleBox: {
97
+ background: ' pink'
98
+ },
99
+ titleText: {
100
+ fontSize: 16 ,
101
+ color: ' #000'
102
+ }
103
+ }
104
+
105
+ < ActionSheet
106
+ ...
107
+ styles= {styles}
108
+ / >
109
+ ` ` `
110
+
136
111
## Props
137
112
113
+ https://github.com/beefe/react-native-actionsheet/blob/master/lib/options.js
114
+
138
115
<table>
139
116
<tr>
140
117
<th>Prop name</th>
@@ -184,4 +161,10 @@ class ExampleB extends React.Component {
184
161
<td>PropTypes.func</td>
185
162
<td>(index) => {}</td>
186
163
</tr>
164
+ <tr>
165
+ <td>styles</td>
166
+ <td>only for ActionSheetCustom</td>
167
+ <td></td>
168
+ <td>{}</td>
169
+ </tr>
187
170
</table>
0 commit comments