From 102abcb86295e902282a3613150e697945fcf6d4 Mon Sep 17 00:00:00 2001 From: xiaoyann <0x0886@gmail.com> Date: Sun, 1 Apr 2018 23:50:58 +0800 Subject: [PATCH] update readme --- README.md | 125 +++++++++++++++++++++++------------------------------- 1 file changed, 54 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index f4bf4ed..2d54c8f 100644 --- a/README.md +++ b/README.md @@ -14,56 +14,32 @@ Cross platform ActionSheet. This component implements a custom ActionSheet and -# Installation +## Install ``` -npm i react-native-actionsheet --save +npm install react-native-actionsheet --save ``` ## Usage -```javascript -import React from 'react' -import { View, Text, StyleSheet, Modal, ListView } from 'react-native' +```js import ActionSheet from 'react-native-actionsheet' -const CANCEL_INDEX = 0 -const DESTRUCTIVE_INDEX = 4 -const options = [ 'Cancel', 'Apple', 'Banana', 'Watermelon', 'Durian' ] -const title = 'Which one do you like?' - -class ExampleA extends React.Component { - constructor(props) { - super(props) - this.state = { - selected: '' - } - this.handlePress = this.handlePress.bind(this) - this.showActionSheet = this.showActionSheet.bind(this) - } - - showActionSheet() { +class Demo extends React.Component { + showActionSheet = () => { this.ActionSheet.show() } - - handlePress(i) { - this.setState({ - selected: i - }) - } - render() { return ( - - I like {options[this.state.selected]} - Example A + + Open ActionSheet this.ActionSheet = o} - title={title} - options={options} - cancelButtonIndex={CANCEL_INDEX} - destructiveButtonIndex={DESTRUCTIVE_INDEX} - onPress={this.handlePress} + title={'Which one do you like ?'} + options={['Apple', 'Banana', 'cancel']} + cancelButtonIndex={2} + destructiveButtonIndex={1} + onPress={(index) => { /* do something */ }} /> ) @@ -72,19 +48,14 @@ class ExampleA extends React.Component { ``` -## Use ActionSheetCustom directly +### Use ActionSheetCustom directly so you can customize option and title -```javascript -import React from 'react' -import { View, Text, StyleSheet, Modal, ListView } from 'react-native' +```js import { ActionSheetCustom as ActionSheet } from 'react-native-actionsheet' -const CANCEL_INDEX = 0 -const DESTRUCTIVE_INDEX = 4 - -const options = [ +const options = [ 'Cancel', 'Apple', Banana, @@ -92,40 +63,21 @@ const options = [ Durian ] -const title = Which one do you like? - -class ExampleB extends React.Component { - constructor(props) { - super(props) - this.state = { - selected: '' - } - this.handlePress = this.handlePress.bind(this) - this.showActionSheet = this.showActionSheet.bind(this) - } - - showActionSheet() { +class Demo extends React.Component { + showActionSheet = () => { this.ActionSheet.show() } - - handlePress(i) { - this.setState({ - selected: i - }) - } - render() { return ( - - I like {options[this.state.selected]} - Example B + + Open ActionSheet this.ActionSheet = o} - title={title} + title={Which one do you like?} options={options} - cancelButtonIndex={CANCEL_INDEX} - destructiveButtonIndex={DESTRUCTIVE_INDEX} - onPress={this.handlePress} + cancelButtonIndex={0} + destructiveButtonIndex={4} + onPress={(index) => { /* do something */ }} /> ) @@ -133,8 +85,33 @@ class ExampleB extends React.Component { } ``` +### How to redesign style ? + +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) . + +```javascript +// example + +const styles = { + titleBox: { + background: 'pink' + }, + titleText: { + fontSize: 16, + color: '#000' + } +} + + +``` + ## Props +https://github.com/beefe/react-native-actionsheet/blob/master/lib/options.js + @@ -184,4 +161,10 @@ class ExampleB extends React.Component { + + + + + +
Prop namePropTypes.func (index) => {}
stylesonly for ActionSheetCustom{}