Skip to content

Commit f3b8237

Browse files
committed
Tab Bar Navigation
1 parent 1048758 commit f3b8237

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

imgs/home.png

292 Bytes
Loading

imgs/tablet.png

211 Bytes
Loading

index.ios.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ import {
33
AppRegistry,
44
} from 'react-native';
55
import App from './src/App'
6-
import { StackNavigator } from 'react-navigation';
6+
import { TabNavigator } from 'react-navigation';
77
import SecondScreen from './src/SecondScreen'
88

99
class reactNavigationSample extends Component {
10-
static navigationOptions = {
11-
title: 'Home Screen',
12-
};
1310

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

1714
return (
18-
<App navigation={ navigation }/>
15+
<App />
1916
);
2017
}
2118
}
2219

23-
const SimpleApp = StackNavigator({
24-
Home: { screen: reactNavigationSample },
25-
SecondScreen: { screen: SecondScreen, title: 'ss' },
20+
const SimpleApp = TabNavigator({
21+
Home: { screen: App },
22+
SecondScreen: { screen: SecondScreen }
2623
});
2724

2825
AppRegistry.registerComponent('reactNavigationSample', () => SimpleApp);

src/App.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
StyleSheet,
44
Text,
55
Button,
6+
Image,
67
View
78
} from 'react-native';
89
import { StackNavigator } from 'react-navigation';
@@ -24,22 +25,31 @@ const styles = StyleSheet.create({
2425
color: '#333333',
2526
marginBottom: 5,
2627
},
28+
tabIcon: {
29+
width: 16,
30+
height: 16,
31+
},
2732
});
2833

29-
const App = (props) => {
30-
const { navigate } = props.navigation;
34+
const App = () => {
3135

3236
return (
3337
<View style={styles.container}>
3438
<Text style={styles.welcome}>
3539
Welcome to React Native Navigation Sample!
3640
</Text>
37-
<Button
38-
onPress={() => navigate('SecondScreen')}
39-
title="Go to Second Screen"
40-
/>
4141
</View>
4242
);
4343
}
4444

45+
App.navigationOptions = {
46+
tabBar: {
47+
icon: () => (
48+
<Image
49+
source={require('../imgs/home.png')}
50+
style={[styles.tabIcon, {tintColor: 'black'}]}
51+
/>
52+
)}
53+
};
54+
4555
export default App

src/SecondScreen.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
22
import {
33
StyleSheet,
44
Text,
5+
Image,
56
View
67
} from 'react-native';
78

@@ -17,6 +18,10 @@ const styles = StyleSheet.create({
1718
textAlign: 'center',
1819
margin: 10,
1920
},
21+
tabIcon: {
22+
width: 16,
23+
height: 16,
24+
},
2025
});
2126

2227
const SecondScreen = () => {
@@ -30,7 +35,13 @@ const SecondScreen = () => {
3035
}
3136

3237
SecondScreen.navigationOptions = {
33-
title: 'Second Screen Title',
38+
tabBar: {
39+
icon: () => (
40+
<Image
41+
source={require('../imgs/home.png')}
42+
style={[styles.tabIcon, {tintColor: 'black'}]}
43+
/>
44+
)}
3445
};
3546

3647
export default SecondScreen

0 commit comments

Comments
 (0)