Skip to content

Commit 102abcb

Browse files
committed
update readme
1 parent 05194f3 commit 102abcb

File tree

1 file changed

+54
-71
lines changed

1 file changed

+54
-71
lines changed

README.md

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -14,56 +14,32 @@ Cross platform ActionSheet. This component implements a custom ActionSheet and
1414
</tbody>
1515
</table>
1616

17-
# Installation
17+
## Install
1818

1919
```
20-
npm i react-native-actionsheet --save
20+
npm install react-native-actionsheet --save
2121
```
2222

2323
## Usage
2424

25-
```javascript
26-
import React from 'react'
27-
import { View, Text, StyleSheet, Modal, ListView } from 'react-native'
25+
```js
2826
import ActionSheet from 'react-native-actionsheet'
2927

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 = () => {
4630
this.ActionSheet.show()
4731
}
48-
49-
handlePress(i) {
50-
this.setState({
51-
selected: i
52-
})
53-
}
54-
5532
render() {
5633
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>
6036
<ActionSheet
6137
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 */ }}
6743
/>
6844
</View>
6945
)
@@ -72,69 +48,70 @@ class ExampleA extends React.Component {
7248
```
7349

7450

75-
## Use ActionSheetCustom directly
51+
### Use ActionSheetCustom directly
7652

7753
so you can customize option and title
7854

79-
```javascript
80-
import React from 'react'
81-
import { View, Text, StyleSheet, Modal, ListView } from 'react-native'
55+
```js
8256
import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet'
8357

84-
const CANCEL_INDEX = 0
85-
const DESTRUCTIVE_INDEX = 4
86-
87-
const options = [
58+
const options = [
8859
'Cancel',
8960
'Apple',
9061
<Text style={{color: 'yellow'}}>Banana</Text>,
9162
'Watermelon',
9263
<Text style={{color: 'red'}}>Durian</Text>
9364
]
9465

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 = () => {
10868
this.ActionSheet.show()
10969
}
110-
111-
handlePress(i) {
112-
this.setState({
113-
selected: i
114-
})
115-
}
116-
11770
render() {
11871
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>
12274
<ActionSheet
12375
ref={o => this.ActionSheet = o}
124-
title={title}
76+
title={<Text style={{color: '#000', fontSize: 18}}>Which one do you like?</Text>}
12577
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 */ }}
12981
/>
13082
</View>
13183
)
13284
}
13385
}
13486
```
13587
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+
136111
## Props
137112
113+
https://github.com/beefe/react-native-actionsheet/blob/master/lib/options.js
114+
138115
<table>
139116
<tr>
140117
<th>Prop name</th>
@@ -184,4 +161,10 @@ class ExampleB extends React.Component {
184161
<td>PropTypes.func</td>
185162
<td>(index) => {}</td>
186163
</tr>
164+
<tr>
165+
<td>styles</td>
166+
<td>only for ActionSheetCustom</td>
167+
<td></td>
168+
<td>{}</td>
169+
</tr>
187170
</table>

0 commit comments

Comments
 (0)