Skip to content

Instantly share code, notes, and snippets.

@PatNeedham
Created October 5, 2017 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatNeedham/082613f9c792089b315ea3b5dfe853ed to your computer and use it in GitHub Desktop.
Save PatNeedham/082613f9c792089b315ea3b5dfe853ed to your computer and use it in GitHub Desktop.
The App.js file I used for the react-navigation pull request #2695
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Button
} from 'react-native';
import { StackNavigator, TabNavigator } from 'react-navigation';
import Dimensions from 'Dimensions'
var {height, width} = Dimensions.get('window')
const viewStyle = {height, width, alignItems: 'center', justifyContent: 'center'}
class Tab1Screen extends React.Component {
static navigationOptions = {
title: 'Tab 1 Screen',
};
render() {
return (
<View style={viewStyle}>
<Text>Tab 1 Screen</Text>
</View>
);
}
}
class Tab2Screen1 extends React.Component {
static navigationOptions = {
title: 'Tab 2 Screen 1',
};
render() {
const { navigate, state } = this.props.navigation;
const { params } = state
return (
<View style={viewStyle}>
<Text>Tab 2 Nested Screen 1</Text>
<Text>Params: {JSON.stringify(params, null, 2)}</Text>
<Button
onPress={() => navigate('Nested2', {exampleKey: 'exampleValue'})}
title="Go to Screen 2"
/>
</View>
);
}
}
class Tab2Screen2 extends React.Component {
static navigationOptions = {
title: 'Tab 2 Screen 2',
};
render() {
const { navigate, state } = this.props.navigation;
const { params } = state
return (
<View style={viewStyle}>
<Text>Tab 2 Nested Screen 2</Text>
<Text>Params: {JSON.stringify(params, null, 2)}</Text>
</View>
);
}
}
const Tab2Screen = StackNavigator({
Nested1: {screen: Tab2Screen1, path: ':id1'},
Nested2: {screen: Tab2Screen2, path: ':id1/:id2'}
})
const TheTabs = TabNavigator({
Tab1: {screen: Tab1Screen, path: 'tab-1'},
Tab2: {screen: Tab2Screen, path: 'tab-2'}
});
class HomeScreen extends React.Component {
render() {
const { navigate} = this.props.navigation;
return (
<View style={viewStyle}>
<Text>Home Screen</Text>
<Button
onPress={() => navigate('TheTabs', {exampleKey: 'exampleValue'})}
title="Go to TheTabs"
/>
</View>
);
}
}
const SimpleApp = StackNavigator({
Home: {screen: HomeScreen, path: 'home'},
TheTabs: {screen: TheTabs, path: 'tabs'}
}, {
mode: 'modal',
headerMode: 'none'
});
const prefix = Platform.OS == 'android' ? 'mychat://mychat/' : 'mychat://';
const MainApp = () => <SimpleApp uriPrefix={prefix} />;
export default MainApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment