-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react-navigation integration for BottomNavigation (#3676)
Co-authored-by: Dimitar Nestorov <dimitar.nestorov@callstack.com>
- Loading branch information
1 parent
252b1a6
commit 7d3bd08
Showing
20 changed files
with
1,763 additions
and
825 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet } from 'react-native'; | ||
|
||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; | ||
import { Text, BottomNavigation } from 'react-native-paper'; | ||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
|
||
const Tab = createBottomTabNavigator(); | ||
|
||
function HomeScreen() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text variant="headlineMedium">Home!</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function SettingsScreen() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text variant="headlineMedium">Settings!</Text> | ||
</View> | ||
); | ||
} | ||
|
||
export default function BottomNavigationBarExample() { | ||
return ( | ||
<Tab.Navigator | ||
screenOptions={{ | ||
headerShown: false, | ||
}} | ||
tabBar={({ navigation, state, descriptors, insets }) => ( | ||
<BottomNavigation.Bar | ||
navigationState={state} | ||
safeAreaInsets={insets} | ||
onTabPress={({ route, preventDefault }) => { | ||
const event = navigation.emit({ | ||
type: 'tabPress', | ||
target: route.key, | ||
canPreventDefault: true, | ||
}); | ||
|
||
if (event.defaultPrevented) { | ||
preventDefault(); | ||
} else { | ||
navigation.navigate(route); | ||
} | ||
}} | ||
renderIcon={({ route, focused, color }) => | ||
descriptors[route.key].options.tabBarIcon?.({ | ||
focused, | ||
color, | ||
size: 24, | ||
}) || null | ||
} | ||
getLabelText={({ route }) => descriptors[route.key].route.name} | ||
/> | ||
)} | ||
> | ||
<Tab.Screen | ||
name="Home" | ||
component={HomeScreen} | ||
options={{ | ||
tabBarIcon: ({ color, size }) => { | ||
return <Icon name="home" size={size} color={color} />; | ||
}, | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Settings" | ||
component={SettingsScreen} | ||
options={{ | ||
tabBarIcon: ({ color, size }) => { | ||
return <Icon name="cog" size={size} color={color} />; | ||
}, | ||
}} | ||
/> | ||
</Tab.Navigator> | ||
); | ||
} | ||
|
||
BottomNavigationBarExample.title = 'Bottom Navigation Bar'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
87 changes: 87 additions & 0 deletions
87
example/src/Examples/MaterialBottomTabNavigatorExample.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
|
||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; | ||
|
||
import { createMaterialBottomTabNavigator } from '../../../src/react-navigation'; | ||
|
||
const Tab = createMaterialBottomTabNavigator(); | ||
|
||
export default function MaterialBottomTabNavigatorExample() { | ||
return ( | ||
<Tab.Navigator | ||
initialRouteName="Feed" | ||
activeColor="#e91e63" | ||
style={styles.tabs} | ||
> | ||
<Tab.Screen | ||
name="Feed" | ||
component={Feed} | ||
options={{ | ||
tabBarLabel: 'Home', | ||
tabBarIcon: ({ color }) => ( | ||
<Icon name="home" color={color} size={26} /> | ||
), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Notifications" | ||
component={Notifications} | ||
options={{ | ||
tabBarLabel: 'Updates', | ||
tabBarIcon: ({ color }) => ( | ||
<Icon name="bell" color={color} size={26} /> | ||
), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="Profile" | ||
component={Profile} | ||
options={{ | ||
tabBarLabel: 'Profile', | ||
tabBarIcon: ({ color }) => ( | ||
<Icon name="account" color={color} size={26} /> | ||
), | ||
}} | ||
/> | ||
</Tab.Navigator> | ||
); | ||
} | ||
|
||
MaterialBottomTabNavigatorExample.title = 'Material Bottom Tab Navigator'; | ||
|
||
function Feed() { | ||
return ( | ||
<View style={styles.screen}> | ||
<Text>Feed!</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function Profile() { | ||
return ( | ||
<View style={styles.screen}> | ||
<Text>Profile!</Text> | ||
</View> | ||
); | ||
} | ||
|
||
function Notifications() { | ||
return ( | ||
<View style={styles.screen}> | ||
<Text>Notifications!</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
screen: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
// eslint-disable-next-line react-native/no-color-literals | ||
tabs: { | ||
backgroundColor: 'tomato', | ||
}, | ||
}); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"main": "../lib/commonjs/react-navigation/index", | ||
"module": "../lib/module/react-navigation/index", | ||
"react-native": "../src/react-navigation/index", | ||
"types": "../lib/typescript/react-navigation/index" | ||
} |
Oops, something went wrong.