Skip to content

Commit 1048758

Browse files
committed
Stack Navigator with two Screens
1 parent e2187d5 commit 1048758

File tree

6 files changed

+3964
-87
lines changed

6 files changed

+3964
-87
lines changed

index.android.js

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,14 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
71
import React, { Component } from 'react';
82
import {
93
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
134
} from 'react-native';
5+
import App from './src/App'
146

15-
export default class reactNavigationSample extends Component {
16-
render() {
17-
return (
18-
<View style={styles.container}>
19-
<Text style={styles.welcome}>
20-
Welcome to React Native!
21-
</Text>
22-
<Text style={styles.instructions}>
23-
To get started, edit index.android.js
24-
</Text>
25-
<Text style={styles.instructions}>
26-
Double tap R on your keyboard to reload,{'\n'}
27-
Shake or press menu button for dev menu
28-
</Text>
29-
</View>
30-
);
31-
}
7+
const reactNavigationSample = () => {
8+
return (
9+
<App />
10+
);
3211
}
3312

34-
const styles = StyleSheet.create({
35-
container: {
36-
flex: 1,
37-
justifyContent: 'center',
38-
alignItems: 'center',
39-
backgroundColor: '#F5FCFF',
40-
},
41-
welcome: {
42-
fontSize: 20,
43-
textAlign: 'center',
44-
margin: 10,
45-
},
46-
instructions: {
47-
textAlign: 'center',
48-
color: '#333333',
49-
marginBottom: 5,
50-
},
51-
});
5213

5314
AppRegistry.registerComponent('reactNavigationSample', () => reactNavigationSample);

index.ios.js

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,28 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
* @flow
5-
*/
6-
71
import React, { Component } from 'react';
82
import {
93
AppRegistry,
10-
StyleSheet,
11-
Text,
12-
View
134
} from 'react-native';
5+
import App from './src/App'
6+
import { StackNavigator } from 'react-navigation';
7+
import SecondScreen from './src/SecondScreen'
8+
9+
class reactNavigationSample extends Component {
10+
static navigationOptions = {
11+
title: 'Home Screen',
12+
};
13+
14+
render(){
15+
const { navigation } = this.props;
1416

15-
export default class reactNavigationSample extends Component {
16-
render() {
1717
return (
18-
<View style={styles.container}>
19-
<Text style={styles.welcome}>
20-
Welcome to React Native!
21-
</Text>
22-
<Text style={styles.instructions}>
23-
To get started, edit index.ios.js
24-
</Text>
25-
<Text style={styles.instructions}>
26-
Press Cmd+R to reload,{'\n'}
27-
Cmd+D or shake for dev menu
28-
</Text>
29-
</View>
18+
<App navigation={ navigation }/>
3019
);
3120
}
3221
}
3322

34-
const styles = StyleSheet.create({
35-
container: {
36-
flex: 1,
37-
justifyContent: 'center',
38-
alignItems: 'center',
39-
backgroundColor: '#F5FCFF',
40-
},
41-
welcome: {
42-
fontSize: 20,
43-
textAlign: 'center',
44-
margin: 10,
45-
},
46-
instructions: {
47-
textAlign: 'center',
48-
color: '#333333',
49-
marginBottom: 5,
50-
},
23+
const SimpleApp = StackNavigator({
24+
Home: { screen: reactNavigationSample },
25+
SecondScreen: { screen: SecondScreen, title: 'ss' },
5126
});
5227

53-
AppRegistry.registerComponent('reactNavigationSample', () => reactNavigationSample);
28+
AppRegistry.registerComponent('reactNavigationSample', () => SimpleApp);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"dependencies": {
1010
"react": "15.4.2",
11-
"react-native": "0.40.0"
11+
"react-native": "0.40.0",
12+
"react-navigation": "^1.0.0-beta.1"
1213
},
1314
"devDependencies": {
1415
"babel-jest": "18.0.0",
@@ -19,4 +20,4 @@
1920
"jest": {
2021
"preset": "react-native"
2122
}
22-
}
23+
}

src/App.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { Component } from 'react';
2+
import {
3+
StyleSheet,
4+
Text,
5+
Button,
6+
View
7+
} from 'react-native';
8+
import { StackNavigator } from 'react-navigation';
9+
10+
const styles = StyleSheet.create({
11+
container: {
12+
flex: 1,
13+
justifyContent: 'center',
14+
alignItems: 'center',
15+
backgroundColor: '#F5FCFF',
16+
},
17+
welcome: {
18+
fontSize: 20,
19+
textAlign: 'center',
20+
margin: 10,
21+
},
22+
instructions: {
23+
textAlign: 'center',
24+
color: '#333333',
25+
marginBottom: 5,
26+
},
27+
});
28+
29+
const App = (props) => {
30+
const { navigate } = props.navigation;
31+
32+
return (
33+
<View style={styles.container}>
34+
<Text style={styles.welcome}>
35+
Welcome to React Native Navigation Sample!
36+
</Text>
37+
<Button
38+
onPress={() => navigate('SecondScreen')}
39+
title="Go to Second Screen"
40+
/>
41+
</View>
42+
);
43+
}
44+
45+
export default App

src/SecondScreen.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { Component } from 'react';
2+
import {
3+
StyleSheet,
4+
Text,
5+
View
6+
} from 'react-native';
7+
8+
const styles = StyleSheet.create({
9+
container: {
10+
flex: 1,
11+
justifyContent: 'center',
12+
alignItems: 'center',
13+
backgroundColor: '#F5FCFF',
14+
},
15+
welcome: {
16+
fontSize: 20,
17+
textAlign: 'center',
18+
margin: 10,
19+
},
20+
});
21+
22+
const SecondScreen = () => {
23+
return (
24+
<View style={styles.container}>
25+
<Text style={styles.welcome}>
26+
THIS IS THE SECOND SCREEN!
27+
</Text>
28+
</View>
29+
);
30+
}
31+
32+
SecondScreen.navigationOptions = {
33+
title: 'Second Screen Title',
34+
};
35+
36+
export default SecondScreen

0 commit comments

Comments
 (0)