Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Makes react native route stable for android. #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ node_modules

# OSX
.DS_Store

.idea/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ React Native Router
===================
Awesome navigation for your React Native app.

** This is a React Native Router fix version. It can be used in Android project. **

![Twitter navigation](http://tristanedwards.me/u/react-native-router/native-router.gif)

Install
-------

Make sure that you are in your React Native project directory and run:

```npm install react-native-router --save```
```npm install react-native-router-fix --save```

Usage
-----
Expand Down
10 changes: 6 additions & 4 deletions components/NavBarContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ var NavBarContainer = React.createClass({
// We render both the current and the previous navbar (for animation)
render: function() {
return (
<View style={[styles.navbarContainer, this.props.style]}>
<View style={styles.navbarContainer}>
<NavBarContent
route={this.state.previousRoute}
route={this.state.previousRoute}
style={this.props.style}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
titleStyle={this.props.titleStyle}
willDisappear="true"
/>
<NavBarContent
route={this.props.currentRoute}
route={this.props.currentRoute}
style={this.props.style}
backButtonComponent={this.props.backButtonComponent}
rightCorner={this.props.rightCorner}
titleStyle={this.props.titleStyle}
Expand All @@ -71,7 +73,7 @@ var styles = StyleSheet.create({
top: 0,
left: 0,
right: 0,
height: 64,
height: React.Platform.OS == 'ios' ? 64 : 48,
backgroundColor: '#5589B7'
}
});
Expand Down
8 changes: 4 additions & 4 deletions components/NavBarContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var NavBarContent = React.createClass({


return (
<View style={[styles.navbar, this.props.route.headerStyle, transitionStyle]}>
<View style={[styles.navbar, this.props.style, this.props.route.headerStyle, transitionStyle]}>
{leftCorner}
{titleComponent}
{rightCorner}
Expand All @@ -137,17 +137,17 @@ var styles = StyleSheet.create({
top: 0,
left: 0,
right: 0,
height: 64, // Default iOS navbar height
height: React.Platform.OS == 'ios' ? 64 : 48, // Default iOS navbar height
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
paddingTop: 13
paddingTop: React.Platform.OS == 'ios' ? 13 : 0
},
navbarText: {
color: 'white',
fontSize: 17,
margin: 10,
marginTop: 14,
marginTop: React.Platform.OS == 'ios' ? 14 : 10,
fontWeight: '600',
textAlign: 'center',
alignItems: 'center',
Expand Down
47 changes: 33 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ var Router = React.createClass({
this.customAction(opts);
}.bind(this);

var isRootView = function() {
return this.state.route.index == 1;
}.bind(this);

var didStartDrag = function(evt) {
var x = evt.nativeEvent.pageX;
if (x < 28) {
Expand Down Expand Up @@ -114,6 +118,7 @@ var Router = React.createClass({
toRoute={goForward}
toBack={goBackwards}
reset={goToFirstRoute}
isRootView={isRootView}
customAction={customAction}
/>
</View>
Expand All @@ -123,11 +128,13 @@ var Router = React.createClass({

render: function() {

// Status bar color
if (this.props.statusBarColor === "black") {
StatusBarIOS.setStyle(0);
} else {
StatusBarIOS.setStyle(1);
// Status bar color, if on iOS
if (React.Platform.OS == 'ios') {
if (this.props.statusBarColor === "black") {
StatusBarIOS.setStyle(0);
} else {
StatusBarIOS.setStyle(1);
}
}

var navigationBar;
Expand All @@ -147,14 +154,26 @@ var Router = React.createClass({
/>
}

return (
<Navigator
initialRoute={this.props.firstRoute}
navigationBar={navigationBar}
renderScene={this.renderScene}
onDidFocus={this.onDidFocus}
/>
)
if (React.Platform.OS == 'ios') {
return (
<Navigator
initialRoute={this.props.firstRoute}
navigationBar={navigationBar}
renderScene={this.renderScene}
onDidFocus={this.onDidFocus}
/>
);
} else {
return (
<Navigator
initialRoute={this.props.firstRoute}
configureScene={(route) => Navigator.SceneConfigs.FadeAndroid}
navigationBar={navigationBar}
renderScene={this.renderScene}
onDidFocus={this.onDidFocus}
/>
);
}
}
});

Expand All @@ -163,7 +182,7 @@ var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
marginTop: 64
marginTop: React.Platform.OS == 'ios' ? 64 : 48
},
});

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "react-native-router",
"version": "0.2.1",
"name": "react-native-router-fix",
"version": "0.2.1-fix-10",
"description": "Awesome navigation for your native app.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/t4t5/react-native-router.git"
"url": "https://github.com/starlight36/react-native-router.git"
},
"keywords": [
"react",
Expand Down