Skip to content

Commit

Permalink
Stack Navigator with two Screens
Browse files Browse the repository at this point in the history
  • Loading branch information
franzejr committed Jan 30, 2017
1 parent e2187d5 commit 1048758
Show file tree
Hide file tree
Showing 6 changed files with 3,964 additions and 87 deletions.
49 changes: 5 additions & 44 deletions index.android.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,14 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import App from './src/App'

export default class reactNavigationSample extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.android.js
</Text>
<Text style={styles.instructions}>
Double tap R on your keyboard to reload,{'\n'}
Shake or press menu button for dev menu
</Text>
</View>
);
}
const reactNavigationSample = () => {
return (
<App />
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

AppRegistry.registerComponent('reactNavigationSample', () => reactNavigationSample);
57 changes: 16 additions & 41 deletions index.ios.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/

import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import App from './src/App'
import { StackNavigator } from 'react-navigation';
import SecondScreen from './src/SecondScreen'

class reactNavigationSample extends Component {
static navigationOptions = {
title: 'Home Screen',
};

render(){
const { navigation } = this.props;

export default class reactNavigationSample extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
<App navigation={ navigation }/>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
const SimpleApp = StackNavigator({
Home: { screen: reactNavigationSample },
SecondScreen: { screen: SecondScreen, title: 'ss' },
});

AppRegistry.registerComponent('reactNavigationSample', () => reactNavigationSample);
AppRegistry.registerComponent('reactNavigationSample', () => SimpleApp);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"dependencies": {
"react": "15.4.2",
"react-native": "0.40.0"
"react-native": "0.40.0",
"react-navigation": "^1.0.0-beta.1"
},
"devDependencies": {
"babel-jest": "18.0.0",
Expand All @@ -19,4 +20,4 @@
"jest": {
"preset": "react-native"
}
}
}
45 changes: 45 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Button,
View
} from 'react-native';
import { StackNavigator } from 'react-navigation';

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

const App = (props) => {
const { navigate } = props.navigation;

return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native Navigation Sample!
</Text>
<Button
onPress={() => navigate('SecondScreen')}
title="Go to Second Screen"
/>
</View>
);
}

export default App
36 changes: 36 additions & 0 deletions src/SecondScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});

const SecondScreen = () => {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
THIS IS THE SECOND SCREEN!
</Text>
</View>
);
}

SecondScreen.navigationOptions = {
title: 'Second Screen Title',
};

export default SecondScreen
Loading

0 comments on commit 1048758

Please sign in to comment.