diff --git a/.babelrc b/.babelrc index 213aad8..3acf317 100644 --- a/.babelrc +++ b/.babelrc @@ -1,5 +1,3 @@ { - "presets": [ - "react-native" - ] + "presets": ["react-native"] } diff --git a/.gitignore b/.gitignore index 7c722ce..40b878d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -node_modules - -# Optional npm cache directory -.npm - -# Optional REPL history -.node_repl_history - -# Example react-native project -Example/ +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index d97236b..a250f4c 100644 --- a/README.md +++ b/README.md @@ -7,97 +7,113 @@ A Higher-order Component for handling back button press on React Native Android npm install --save react-native-back-android ``` -# Usage (Take Navigator as an example. Can be used in any scenario.) -Root component +# Usage +(Take Navigator as an example. Can be used in any scenario.) + ``` -... -import backAndroid from 'react-native-back-android'; +import React, { Component } from 'react' +import { AppRegistry, Button, Text, View, Alert } from 'react-native' +import { StackNavigator } from 'react-navigation' +import backAndroid, { + hardwareBackPress, + exitApp +} from 'react-native-back-android' -class Example extends Component { - render() { - return ( - { - if (route.index === 0) { - return ( - - ); - } else { - return ( - - ); - } - }} - style={{padding: 100}} - /> +class HomeScreen extends React.Component { + static navigationOptions = { + title: 'Welcome' + } + // reserved function for handling hardware back press + handleHardwareBackPress = () => { + Alert.alert( + 'Quiting', + 'Want to quit?', + [ + { + text: 'Cancel', + onPress: () => console.log('Cancel Pressed'), + style: 'cancel' + }, + { text: 'OK', onPress: () => exitApp() } + ], + { cancelable: false } ); + // return true to stop bubbling + return true + }; + render () { + const { navigate } = this.props.navigation + return ( + + Hello, Chat App! +