123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- /**
- * @flow
- */
- import type {
- NavigationScreenProp,
- NavigationEventSubscription,
- } from 'react-navigation';
- import React from 'react';
- import { Platform, ScrollView, StatusBar, View } from 'react-native';
- import { SafeAreaView, createBottomTabNavigator } from 'react-navigation';
- import Ionicons from 'react-native-vector-icons/Ionicons';
- import SampleText from './SampleText';
- import { Button } from './commonComponents/ButtonWithMargin';
- const MyNavScreen = ({ navigation, banner }) => (
- <SafeAreaView forceInset={{ horizontal: 'always', top: 'always' }}>
- <SampleText>{banner}</SampleText>
- <Button
- onPress={() => navigation.navigate('Home')}
- title="Go to home tab"
- />
- <Button
- onPress={() => navigation.navigate('Settings')}
- title="Go to settings tab"
- />
- <Button onPress={() => navigation.goBack(null)} title="Go back" />
- <StatusBar barStyle="default" />
- </SafeAreaView>
- );
- const MyHomeScreen = ({ navigation }) => (
- <MyNavScreen banner="Home Tab" navigation={navigation} />
- );
- MyHomeScreen.navigationOptions = {
- tabBarTestIDProps: {
- testID: 'TEST_ID_HOME',
- accessibilityLabel: 'TEST_ID_HOME_ACLBL',
- },
- tabBarLabel: 'Home',
- tabBarIcon: ({ tintColor, focused }) => (
- <Ionicons
- name={focused ? 'ios-home' : 'ios-home-outline'}
- size={26}
- style={{ color: tintColor }}
- />
- ),
- };
- type MyPeopleScreenProps = {
- navigation: NavigationScreenProp<*>,
- };
- class MyPeopleScreen extends React.Component<MyPeopleScreenProps> {
- _s0: NavigationEventSubscription;
- _s1: NavigationEventSubscription;
- _s2: NavigationEventSubscription;
- _s3: NavigationEventSubscription;
- static navigationOptions = {
- tabBarLabel: 'People',
- tabBarIcon: ({ tintColor, focused }) => (
- <Ionicons
- name={focused ? 'ios-people' : 'ios-people-outline'}
- size={26}
- style={{ color: tintColor }}
- />
- ),
- };
- componentDidMount() {
- this._s0 = this.props.navigation.addListener('willFocus', this._onEvent);
- this._s1 = this.props.navigation.addListener('didFocus', this._onEvent);
- this._s2 = this.props.navigation.addListener('willBlur', this._onEvent);
- this._s3 = this.props.navigation.addListener('didBlur', this._onEvent);
- }
- componentWillUnmount() {
- this._s0.remove();
- this._s1.remove();
- this._s2.remove();
- this._s3.remove();
- }
- _onEvent = a => {
- console.log('EVENT ON PEOPLE TAB', a.type, a);
- };
- render() {
- const { navigation } = this.props;
- return <MyNavScreen banner="People Tab" navigation={navigation} />;
- }
- }
- type MyChatScreenProps = {
- navigation: NavigationScreenProp<*>,
- };
- class MyChatScreen extends React.Component<MyChatScreenProps> {
- _s0: NavigationEventSubscription;
- _s1: NavigationEventSubscription;
- _s2: NavigationEventSubscription;
- _s3: NavigationEventSubscription;
- static navigationOptions = {
- tabBarLabel: 'Chat',
- tabBarIcon: ({ tintColor, focused }) => (
- <Ionicons
- name={focused ? 'ios-chatboxes' : 'ios-chatboxes-outline'}
- size={26}
- style={{ color: tintColor }}
- />
- ),
- };
- componentDidMount() {
- this._s0 = this.props.navigation.addListener('willFocus', this._onEvent);
- this._s1 = this.props.navigation.addListener('didFocus', this._onEvent);
- this._s2 = this.props.navigation.addListener('willBlur', this._onEvent);
- this._s3 = this.props.navigation.addListener('didBlur', this._onEvent);
- }
- componentWillUnmount() {
- this._s0.remove();
- this._s1.remove();
- this._s2.remove();
- this._s3.remove();
- }
- _onEvent = a => {
- console.log('EVENT ON CHAT TAB', a.type, a);
- };
- render() {
- const { navigation } = this.props;
- return <MyNavScreen banner="Chat Tab" navigation={navigation} />;
- }
- }
- const MySettingsScreen = ({ navigation }) => (
- <MyNavScreen banner="Settings Tab" navigation={navigation} />
- );
- MySettingsScreen.navigationOptions = {
- tabBarLabel: 'Settings',
- tabBarIcon: ({ tintColor, focused }) => (
- <Ionicons
- name={focused ? 'ios-settings' : 'ios-settings-outline'}
- size={26}
- style={{ color: tintColor }}
- />
- ),
- };
- const SimpleTabs = createBottomTabNavigator(
- {
- Home: {
- screen: MyHomeScreen,
- path: '',
- },
- People: {
- screen: MyPeopleScreen,
- path: 'cart',
- },
- Chat: {
- screen: MyChatScreen,
- path: 'chat',
- },
- Settings: {
- screen: MySettingsScreen,
- path: 'settings',
- },
- },
- {
- tabBarOptions: {
- activeTintColor: '#e91e63',
- },
- }
- );
- type SimpleTabsContainerProps = {
- navigation: NavigationScreenProp<*>,
- };
- class SimpleTabsContainer extends React.Component<SimpleTabsContainerProps> {
- static router = SimpleTabs.router;
- _s0: NavigationEventSubscription;
- _s1: NavigationEventSubscription;
- _s2: NavigationEventSubscription;
- _s3: NavigationEventSubscription;
- componentDidMount() {
- this._s0 = this.props.navigation.addListener('willFocus', this._onAction);
- this._s1 = this.props.navigation.addListener('didFocus', this._onAction);
- this._s2 = this.props.navigation.addListener('willBlur', this._onAction);
- this._s3 = this.props.navigation.addListener('didBlur', this._onAction);
- }
- componentWillUnmount() {
- this._s0.remove();
- this._s1.remove();
- this._s2.remove();
- this._s3.remove();
- }
- _onAction = a => {
- console.log('TABS EVENT', a.type, a);
- };
- render() {
- return <SimpleTabs navigation={this.props.navigation} />;
- }
- }
- export default SimpleTabsContainer;
|