Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomejerry committed May 29, 2017
1 parent 41b2587 commit 64d5249
Show file tree
Hide file tree
Showing 11 changed files with 4,280 additions and 206 deletions.
4 changes: 1 addition & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"presets": [
"react-native"
]
"presets": ["react-native"]
}
37 changes: 1 addition & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
146 changes: 81 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Navigator
initialRoute={routes[0]}
initialRouteStack={routes}
renderScene={(route, navigator) => {
if (route.index === 0) {
return (
<EnhancedScene1
navigator={navigator}
/>
);
} else {
return (
<EnhancedScene2
navigator={navigator}
/>
);
}
}}
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 (
<View>
<Text>Hello, Chat App!</Text>
<Button onPress={() => navigate('Chat')} title='Chat with Lucy' />
</View>
)
}
}
const EnhancedExample = backAndroid(Example);
export default EnhancedExample;
```

Any component that wants to handle backButtonPress
```
...
import { hardwareBackPress, exitApp } from 'react-native-back-android';
class Scene1 extends Component {
handleHardwareBackPress() {
console.log('* Scene1 back press');
exitApp();
return true;
class ChatScreen extends React.Component {
static navigationOptions = {
title: 'Chat with Lucy'
}
render() {
// reserved function for handling hardware back press
handleHardwareBackPress = () => {
const { goBack } = this.props.navigation
Alert.alert(
'Going Back',
'Want to go back?',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{ text: 'OK', onPress: () => goBack() }
],
{ cancelable: false }
);
// return true to stop bubbling
return true
};
render () {
return (
<View>
<Text>Scene1</Text>
<TouchableHighlight
onPress={() => {
this.props.navigator.push(routes[1]);
}}
>
<Text>Go To Scene2</Text>
</TouchableHighlight>
<Text>Chat with Lucy</Text>
</View>
);
)
}
}
const EnhancedScene1 = hardwareBackPress(Scene1);
export default EnhanceScene1;
```
const ReactNativeBackAndroidExample = StackNavigator({
Home: { screen: hardwareBackPress(HomeScreen) },
Chat: { screen: hardwareBackPress(ChatScreen) }
})
AppRegistry.registerComponent('ReactNativeBackAndroidExample', () =>
backAndroid(ReactNativeBackAndroidExample)
)
```
Stateless component
```
...
import { hardwareBackPress } from 'react-native-back-android';
const Scene2 = ({ navigator }) => (
const Stateless = ({ navigator }) => (
<View>
<Text>Scene2</Text>
<TouchableHighlight
<Text>Stateless</Text>
<Button
title="stateless"
onPress={() => {
navigator.pop();
}}
>
<Text>Go Back To Scene2</Text>
</TouchableHighlight>
/>
</View>
);
const handleBackButtonPress = ({ navigator }) => {
navigator.pop();
const handleBackButtonPress = ({ navigation }) => {
navigation.goBack();
return true;
};
const EnhancedScene2 = hardwareBackPress(Scene2, handleBackButtonPress);
const EnhancedStateless = hardwareBackPress(Stateless, handleBackButtonPress);
export default EnhancedScene2;
export default EnhancedStateless;
```
10 changes: 6 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
machine:
node:
version: 5.7.1
version: 6.10.3

dependencies:
pre:
- npm install [email protected] [email protected]
override:
- npm install --only=dev
- npm install

test:
override:
- npm run test

deployment:
npm:
Expand Down
41 changes: 28 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
{
"name": "react-native-back-android",
"version": "2.0.1",
"version": "3.0.0",
"description": "A Higher-order Component for handling back button press on React Native Android",
"main": "index.js",
"scripts": {
"test": "mocha --require react-native-mock/mock.js --compilers js:babel-core/register --recursive src/test/*.js",
"test": "jest",
"test-update": "npm run test -- --updateSnapshot",
"lint-staged": "lint-staged",
"lint": "standard 'src/**/*.js'",
"2npm": "publish"
},
"standard": {
"env": [
"jest"
],
"parser": "babel-eslint"
},
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": "lint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AwesomeJerry/react-native-back-android.git"
Expand All @@ -24,19 +37,21 @@
},
"homepage": "https://github.com/AwesomeJerry/react-native-back-android#readme",
"peerDependencies": {
"react": "15.0.2",
"react-native": "0.26.2"
"react": "^16.0.0-alpha.6",
"react-native": "^0.44.2"
},
"devDependencies": {
"babel-core": "6.9.1",
"babel-preset-react-native": "1.9.0",
"chai": "3.5.0",
"enzyme": "2.3.0",
"mocha": "2.5.3",
"babel-eslint": "^7.2.3",
"babel-jest": "20.0.3",
"babel-preset-react-native": "1.9.2",
"jest": "20.0.4",
"lint-staged": "^3.5.0",
"pre-commit": "^1.2.2",
"publish": "0.6.0",
"react": "15.0.2",
"react-addons-test-utils": "15.0.2",
"react-dom": "15.0.2",
"react-native-mock": "0.2.2"
"react-test-renderer": "16.0.0-alpha.6",
"standard": "^10.0.2"
},
"dependencies": {
"prop-types": "^15.5.10"
}
}
Loading

0 comments on commit 64d5249

Please sign in to comment.