Skip to content
This repository was archived by the owner on Feb 10, 2020. It is now read-only.

Commit b87d78f

Browse files
Merge pull request #22 from ekonstantinidis/android-back-button
[Android] Fix back button (hardware)
2 parents ff13ecd + 0d7f439 commit b87d78f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

App/AppContainer.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react'; // eslint-disable-line no-unused-vars
22
import { connect } from 'react-redux';
33

44
import {
5+
BackAndroid,
56
Navigator,
67
StyleSheet
78
} from 'react-native';
@@ -22,7 +23,26 @@ const styles = StyleSheet.create({
2223
});
2324

2425
class AppContainer extends Component {
26+
27+
constructor(props) {
28+
super(props);
29+
30+
this.navigator;
31+
}
32+
33+
componentWillMount() {
34+
BackAndroid.addEventListener('hardwareBackPress', () => {
35+
if (this.navigator && this.navigator.getCurrentRoutes().length > 1) {
36+
this.navigator.pop();
37+
return true;
38+
}
39+
return false;
40+
});
41+
}
42+
2543
renderScene(route, navigator) {
44+
this.navigator = navigator;
45+
2646
return (
2747
<SceneContainer
2848
title={route.title}
@@ -53,7 +73,7 @@ class AppContainer extends Component {
5373
return (
5474
<Navigator
5575
initialRoute={initialRoute}
56-
renderScene={this.renderScene}
76+
renderScene={this.renderScene.bind(this)}
5777
navigationBar={<NavigationBar style={styles.navbar} routeMapper={RouteMapper} />} />
5878
);
5979
}

App/Routes/SettingsView.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
33

44
import {
55
Linking,
6+
Platform,
67
StyleSheet,
78
Text,
89
TouchableHighlight,
@@ -44,6 +45,8 @@ class SettingsView extends Component {
4445
}
4546

4647
render() {
48+
const availableOn = (Platform.OS === 'ios') ? 'OSX, iOS' : 'OSX, iOS and Android';
49+
4750
return (
4851
<View style={styles.container}>
4952
<View style={styles.settingsWrapper}>
@@ -72,7 +75,7 @@ class SettingsView extends Component {
7275
<Text style={styles.footerText}>www.gitify.io</Text>
7376
</TouchableHighlight>
7477

75-
<Text style={styles.footerText}>Available on OSX, iOS and Android.</Text>
78+
<Text style={styles.footerText}>Available on {availableOn}.</Text>
7679
<Text style={styles.footerText}>Made with ❤ in Brighton.</Text>
7780
<Text style={styles.footerText}>Copyright (c) 2016 Emmanouil Konstantinidis</Text>
7881
</View>

0 commit comments

Comments
 (0)