import React, { Component, PropTypes } from 'react'; import { AppRegistry, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import Exponent from 'exponent'; import { createRouter, NavigationProvider, StackNavigation, NavigationStyles, TabNavigation, TabNavigationItem as TabItem, } from '@exponent/ex-navigation'; const AppRouter = createRouter(() => ({ modal: () => ModalContainer, landing: () => LandingScreen, another: () => AnotherRouteScreen, nestedNav: () => NestedNavigationScreen, tabLanding: () => TabLandingScreen, })); class LandingScreen extends Component { static route = { navigationBar: { title: 'Landing', }, } componentDidMount() { this.props.navigator.showLocalAlert('Hello!', { text: {color: '#fff'}, container: {backgroundColor: 'red'}, }); } render() { return ( Go forward Go back Open a modal (that has tabs)! ); } onPressForward = () => { this.props.navigator.push( AppRouter.getRoute('another', { text: 'Some dynamic text!', }) ); } onPressBack = () => { try { const parentNavigator = this.props.navigator.getParentNavigator(); parentNavigator.pop(); } catch (e) {} } onPressOpenModal = () => { const rootNavigator = this.props.navigation.getNavigator('root'); rootNavigator.push(AppRouter.getRoute('modal', { initialRoute: 'tabLanding', })); } } class AnotherRouteScreen extends Component { static propTypes = { text: PropTypes.string.isRequired, }; static route = { navigationBar: { title: 'Another Route', }, } state = { otherText: '', } componentDidMount() { const ee = this.props.route.getEventEmitter(); this.listener = ee.addListener('hello', () => { this.setState({ otherText: 'some other text', }); }); setTimeout(() => { ee.emit('hello'); }, 5000); } componentWillUnmount() { if (this.listener) { this.listener.remove(); } } render() { return ( {this.state.otherText} {this.props.text} Go forward Go back Replace Reset! ); } onPressForward = () => { this.props.navigator.push( AppRouter.getRoute('nestedNav') ); } onPressBack = () => { this.props.navigator.pop(); } onPressReplace = () => { this.props.navigator.replace(AppRouter.getRoute('tabLanding')); } onPressReset = () => { this.props.navigation.getNavigator('root').immediatelyResetStack([ AppRouter.getRoute('landing'), ]); } } class NestedNavigationScreen extends Component { static route = { navigationBar: { visible: false, }, } render() { return ( ); } } class ModalContainer extends Component { static propTypes = { initialRoute: PropTypes.string.isRequired, }; static route = { styles: NavigationStyles.FloatVertical, navigationBar: { visible: false, }, } render() { return ( ); } } class TabLandingScreen extends Component { render() { return ( ); } } class App extends Component { render() { return ( ); } } export default class AppContainer extends Component { render() { return ( ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, selectedTab: { backgroundColor: '#eee', }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, }); AppRegistry.registerComponent('main', () => AppContainer);