Skip to content

Instantly share code, notes, and snippets.

@divyanshu013
Created February 19, 2018 08:42
Show Gist options
  • Save divyanshu013/0b6cef2c3a0d6c8a7f9610c07d369e4d to your computer and use it in GitHub Desktop.
Save divyanshu013/0b6cef2c3a0d6c8a7f9610c07d369e4d to your computer and use it in GitHub Desktop.
The main tab navigation logic for todos-native app
import React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import Colors from '../constants/Colors';
import CONSTANTS from '../constants';
import TodosScreen from '../screens/TodosScreen';
const commonNavigationOptions = ({ navigation }) => ({
header: null,
title: navigation.state.routeName,
});
// we just pass these to render different routes
const routeOptions = {
screen: TodosScreen,
navigationOptions: commonNavigationOptions,
};
// different routes for all, active and completed todos
const TabNav = TabNavigator(
{
[CONSTANTS.ALL]: routeOptions,
[CONSTANTS.ACTIVE]: routeOptions,
[CONSTANTS.COMPLETED]: routeOptions,
},
{
navigationOptions: ({ navigation }) => ({
// this tells us which icon to render on the tabs
tabBarIcon: ({ focused }) => {
const { routeName } = navigation.state;
let iconName;
switch (routeName) {
case CONSTANTS.ALL:
iconName = 'format-list-bulleted';
break;
case CONSTANTS.ACTIVE:
iconName = 'filter-center-focus';
break;
case CONSTANTS.COMPLETED:
iconName = 'playlist-add-check';
}
return (
<MaterialIcons
name={iconName}
size={28}
style={{ marginBottom: -3 }}
color={focused ? Colors.tabIconSelected : Colors.tabIconDefault}
/>
);
},
}),
// for rendering the tabs at bottom
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
animationEnabled: true,
swipeEnabled: true,
},
);
export default TabNav;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment