mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-25 09:35:19 +00:00
205 lines
5.4 KiB
JavaScript
205 lines
5.4 KiB
JavaScript
/**
|
|
* @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;
|