Skip to content

Instantly share code, notes, and snippets.

@wobsoriano
Created February 16, 2020 02:33
Show Gist options
  • Save wobsoriano/7f2d490acadbf33c7874b7e2fb82773a to your computer and use it in GitHub Desktop.
Save wobsoriano/7f2d490acadbf33c7874b7e2fb82773a to your computer and use it in GitHub Desktop.
Nativebase Footer Tabs with react-navigation 5 BottomTabNavigator
import React from 'react';
import {
Container,
Header,
Content,
Footer,
FooterTab,
Button,
Icon,
Text,
View,
} from 'native-base';
import {NavigationContainer} from '@react-navigation/native';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
const Home = () => {
return (
<React.Fragment>
<Header />
<Content>
<View>
<Text>Home</Text>
</View>
</Content>
</React.Fragment>
);
};
const Settings = () => {
return (
<React.Fragment>
<Header />
<Content>
<View>
<Text>Settings</Text>
</View>
</Content>
</React.Fragment>
);
};
const BottomNavigation = ({state, descriptors, navigation}) => {
return (
<Footer>
<FooterTab>
{state.routes.map((route, index) => {
const {options} = descriptors[route.key];
const label =
options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;
const isFocused = state.index === index;
const onPress = () => {
const event = navigation.emit({
type: 'tabPress',
target: route.key,
});
if (!isFocused && !event.defaultPrevented) {
navigation.navigate(route.name);
}
};
const onLongPress = () => {
navigation.emit({
type: 'tabLongPress',
target: route.key,
});
};
return (
<Button
active={isFocused}
vertical
onPress={onPress}
onLongPress={onLongPress}
key={index}>
<Icon name={options.icon} />
<Text>{label}</Text>
</Button>
);
})}
</FooterTab>
</Footer>
);
};
const App = () => {
return (
<Container>
<NavigationContainer>
<Tab.Navigator tabBar={props => <BottomNavigation {...props} />}>
<Tab.Screen name="Home" component={Home} options={{icon: 'home'}} />
<Tab.Screen
name="Settings"
component={Settings}
options={{icon: 'settings'}}
/>
</Tab.Navigator>
</NavigationContainer>
</Container>
);
};
export default App;
@pk936
Copy link

pk936 commented Jul 27, 2020

I tried tihis, but it shows header. But content is empty.

@mlkmte
Copy link

mlkmte commented Aug 20, 2020

I how to change bg color and other ?? i try but nothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment