Skip to content

Instantly share code, notes, and snippets.

@sealskej
Created January 10, 2017 11:28
Show Gist options
  • Save sealskej/a981e61d52567bcfeeacc9ade3ab3e0c to your computer and use it in GitHub Desktop.
Save sealskej/a981e61d52567bcfeeacc9ade3ab3e0c to your computer and use it in GitHub Desktop.
import React from 'react';
import {
AppRegistry,
Text,
View,
} from 'react-native';
import {
createRouter,
NavigationProvider,
StackNavigation,
} from '@exponent/ex-navigation';
const Router = createRouter(() => ({
splash: () => SplashScreen,
a: () => AScreen,
b: () => BScreen,
c: () => CScreen,
}));
class App extends React.Component {
render() {
return (
<NavigationProvider router={Router}>
<StackNavigation initialRoute={Router.getRoute('splash')}/>
</NavigationProvider>
);
}
}
class SplashScreen extends React.Component {
componentDidMount() {
const routes = [Router.getRoute('a'), Router.getRoute('b'), Router.getRoute('c')];
this.props.navigator.immediatelyResetStack(routes, 2)
}
render() {
return null;
}
}
class AScreen extends React.Component {
static route = {
navigationBar: {
title: 'A',
}
};
render() {
return (
<View style={{alignItems: 'center', justifyContent: 'center', flex: 1}}>
<Text>A!</Text>
<Text onPress={this._goToA}>
Push A
</Text>
</View>
)
}
_goToA = () => {
this.props.navigator.push(Router.getRoute('b'));
}
}
class BScreen extends React.Component {
static route = {
navigationBar: {
title: 'B',
}
};
render() {
return (
<View style={{alignItems: 'center', justifyContent: 'center', flex: 1}}>
<Text>B!</Text>
<Text onPress={this._goToC}>
Push C
</Text>
<Text onPress={this._goBackHome}>
Go back to A
</Text>
</View>
)
}
_goToC = () => {
this.props.navigator.push(Router.getRoute('c'));
};
_goBackHome = () => {
this.props.navigator.pop();
}
}
class CScreen extends React.Component {
static route = {
navigationBar: {
title: 'C',
}
};
render() {
return (
<View style={{alignItems: 'center', justifyContent: 'center', flex: 1}}>
<Text>C!</Text>
<Text onPress={this._goBackHome}>
Go back to B
</Text>
</View>
)
}
_goBackHome = () => {
this.props.navigator.pop();
}
}
AppRegistry.registerComponent('untitled1', () => App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment