Created
February 16, 2020 02:33
-
-
Save wobsoriano/7f2d490acadbf33c7874b7e2fb82773a to your computer and use it in GitHub Desktop.
Nativebase Footer Tabs with react-navigation 5 BottomTabNavigator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
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
I tried tihis, but it shows header. But content is empty.