Skip to content

Instantly share code, notes, and snippets.

@avblink
Created November 30, 2017 20:43
Show Gist options
  • Save avblink/af5f9fa8edcb27ef526a543258792717 to your computer and use it in GitHub Desktop.
Save avblink/af5f9fa8edcb27ef526a543258792717 to your computer and use it in GitHub Desktop.
React Native nested navigation example. Fixed header navigation with nested tab navigation.
import React, { Component } from 'react';
import {
View,
} from 'react-native';
import MyStacksOverTabs from '../config/routes';
export default class NavigationScreen extends Component {
render() {
return (
<MyStacksOverTabs />
);
}
}
import React from 'react';
import { Button, Text, View } from 'react-native';
import { StackNavigator, TabNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
const { navigation } = this.props;
return (
<View style={{ flex: 1 }}>
<Text> Welcome Home </Text>
<Button title='Open FavScreen' onPress={() => { navigation.navigate('FavScreen') }} />
<MyTabsNavigation screenProps={{ rootNavigation: navigation }} />
</View>
);
}
}
class FavScreen extends React.Component {
render() {
const { navigation } = this.props;
return (
<View>
<Text>Favourites</Text>
<Button title='Go Back' onPress={() => { navigation.goBack() }} />
</View>
);
}
}
class Tab1 extends React.Component {
render() {
const { navigation } = this.props;
return (
<Button title='Open Tab 2' onPress={() => { navigation.navigate('Tab2') }} />
);
}
}
class Tab2 extends React.Component {
render() {
const { navigation } = this.props;
const { rootNavigation } = this.props.screenProps;
return (
<Button title='Open FavScreen' onPress={() => { rootNavigation.navigate('FavScreen') }} />
);
}
}
export const MyTabsNavigation = TabNavigator({
Tab1: {
screen: Tab1,
},
Tab2: {
screen: Tab2,
},
});
export default MyStacksOverTabs = StackNavigator({
HomeScreen: {
screen: HomeScreen,
},
FavScreen: {
screen: FavScreen,
},
},
{
mode: 'modal',
headerMode: 'none',
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment