2018-01-17 14:43:28 -08:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
Platform,
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
StatusBar,
|
|
|
|
Text,
|
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
|
|
|
} from 'react-native';
|
|
|
|
import {
|
|
|
|
createNavigator,
|
|
|
|
createNavigationContainer,
|
|
|
|
SafeAreaView,
|
|
|
|
TabRouter,
|
|
|
|
} from 'react-navigation';
|
|
|
|
import SampleText from './SampleText';
|
2018-03-13 21:13:19 +01:00
|
|
|
import { Button } from './commonComponents/ButtonWithMargin';
|
2018-01-17 14:43:28 -08:00
|
|
|
|
|
|
|
const MyNavScreen = ({ navigation, banner }) => (
|
|
|
|
<ScrollView>
|
|
|
|
<SafeAreaView forceInset={{ horizontal: 'always' }}>
|
|
|
|
<SampleText>{banner}</SampleText>
|
|
|
|
<Button
|
|
|
|
onPress={() => {
|
|
|
|
navigation.goBack(null);
|
|
|
|
}}
|
|
|
|
title="Go back"
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
<StatusBar barStyle="default" />
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
|
|
|
|
const MyHomeScreen = ({ navigation }) => (
|
|
|
|
<MyNavScreen banner="Home Screen" navigation={navigation} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const MyNotificationsScreen = ({ navigation }) => (
|
|
|
|
<MyNavScreen banner="Notifications Screen" navigation={navigation} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const MySettingsScreen = ({ navigation }) => (
|
|
|
|
<MyNavScreen banner="Settings Screen" navigation={navigation} />
|
|
|
|
);
|
|
|
|
|
|
|
|
const CustomTabBar = ({ navigation }) => {
|
|
|
|
const { routes } = navigation.state;
|
|
|
|
return (
|
|
|
|
<SafeAreaView style={styles.tabContainer}>
|
|
|
|
{routes.map(route => (
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => navigation.navigate(route.routeName)}
|
|
|
|
style={styles.tab}
|
|
|
|
key={route.routeName}
|
|
|
|
>
|
|
|
|
<Text>{route.routeName}</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
))}
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-02-27 17:27:58 -08:00
|
|
|
const CustomTabView = ({ descriptors, navigation }) => {
|
2018-01-17 14:43:28 -08:00
|
|
|
const { routes, index } = navigation.state;
|
2018-02-27 17:27:58 -08:00
|
|
|
const descriptor = descriptors[routes[index].key];
|
|
|
|
const ActiveScreen = descriptor.getComponent();
|
2018-01-17 14:43:28 -08:00
|
|
|
return (
|
|
|
|
<SafeAreaView forceInset={{ top: 'always' }}>
|
|
|
|
<CustomTabBar navigation={navigation} />
|
2018-02-27 17:27:58 -08:00
|
|
|
<ActiveScreen navigation={descriptor.navigation} />
|
2018-01-17 14:43:28 -08:00
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const CustomTabRouter = TabRouter(
|
|
|
|
{
|
|
|
|
Home: {
|
|
|
|
screen: MyHomeScreen,
|
|
|
|
path: '',
|
|
|
|
},
|
|
|
|
Notifications: {
|
|
|
|
screen: MyNotificationsScreen,
|
|
|
|
path: 'notifications',
|
|
|
|
},
|
|
|
|
Settings: {
|
|
|
|
screen: MySettingsScreen,
|
|
|
|
path: 'settings',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Change this to start on a different tab
|
|
|
|
initialRouteName: 'Home',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const CustomTabs = createNavigationContainer(
|
2018-02-27 17:27:58 -08:00
|
|
|
createNavigator(CustomTabView, CustomTabRouter, {})
|
2018-01-17 14:43:28 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
tabContainer: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
height: 48,
|
|
|
|
},
|
|
|
|
tab: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
margin: 4,
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: '#ddd',
|
|
|
|
borderRadius: 4,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default CustomTabs;
|