-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add React Navigation Bottom Tabs (rebased) (#35)
* Add reactNavigation, and reactNavigationBottomTabs files into boilerplate template * Set up app with bottom tab navigation by default * Remove addNavigation command and its tests Rebase of #28. --------- Co-authored-by: William Larry <[email protected]> Co-authored-by: Stephen Hanson <[email protected]>
- Loading branch information
1 parent
d644800
commit ab38f6b
Showing
17 changed files
with
168 additions
and
104 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
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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,16 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import React from 'react'; | ||
import HomeScreen from 'src/screens/HomeScreen/HomeScreen'; | ||
import InformationScreen from '../screens/InformationScreen/InformationScreen'; | ||
import { DashboardTabParamList } from './navigatorTypes'; | ||
|
||
const Dashboard = createNativeStackNavigator<DashboardTabParamList>(); | ||
|
||
export default function DashboardStack() { | ||
return ( | ||
<Dashboard.Navigator> | ||
<Dashboard.Screen name="Home" component={HomeScreen} /> | ||
<Dashboard.Screen name="Information" component={InformationScreen} /> | ||
</Dashboard.Navigator> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import HomeScreen from 'src/screens/HomeScreen/HomeScreen'; | ||
import { | ||
NativeStackNavigationOptions, | ||
createNativeStackNavigator, | ||
} from '@react-navigation/native-stack'; | ||
import TabNavigator from './TabNavigator'; | ||
|
||
const navigatorScreenOptions: NativeStackNavigationOptions = { | ||
headerShadowVisible: false, | ||
}; | ||
|
||
const Stack = createNativeStackNavigator(); | ||
|
||
export default function RootNavigator() { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen name="Home" component={HomeScreen} /> | ||
<Stack.Navigator screenOptions={navigatorScreenOptions}> | ||
<Stack.Screen | ||
name="Tabs" | ||
component={TabNavigator} | ||
options={{ headerShown: false }} | ||
/> | ||
|
||
{/* | ||
screens that are navigable outside of tabs go here. This can include: | ||
- authentication screens (only render tab navigator conditionally) | ||
- screens that should not display bottom tab bar and that might be | ||
navigated to from a screen from multiple tabs | ||
*/} | ||
</Stack.Navigator> | ||
); | ||
} |
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,50 @@ | ||
import { MaterialCommunityIcons } from '@expo/vector-icons'; | ||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; | ||
import SettingsScreen from '../screens/SettingsScreen/SettingsScreen'; | ||
import DashboardStack from './DashboardStack'; | ||
import { TabsParamList } from './navigatorTypes'; | ||
|
||
const Tab = createBottomTabNavigator<TabsParamList>(); | ||
|
||
function HomeIcon({ focused = false, color = 'gray' }) { | ||
return <MaterialCommunityIcons name="home" color={color} size={26} />; | ||
} | ||
|
||
function AccountIcon({ focused = false, color = 'gray' }) { | ||
return ( | ||
<MaterialCommunityIcons name="account-circle" color={color} size={26} /> | ||
); | ||
} | ||
|
||
export default function TabNavigator() { | ||
return ( | ||
<Tab.Navigator | ||
screenOptions={{ | ||
tabBarLabelPosition: 'below-icon', | ||
tabBarStyle: { | ||
elevation: 0, | ||
backgroundColor: 'transparent', | ||
borderTopColor: '#eee', | ||
borderTopWidth: 1, | ||
paddingBottom: 2, | ||
}, | ||
}} | ||
> | ||
<Tab.Screen | ||
name="DashboardTab" | ||
component={DashboardStack} | ||
options={{ | ||
headerShown: false, | ||
tabBarIcon: HomeIcon, | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="SettingsTab" | ||
component={SettingsScreen} | ||
options={{ | ||
tabBarIcon: AccountIcon, | ||
}} | ||
/> | ||
</Tab.Navigator> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,40 @@ | ||
// add types for navigation here | ||
// key: screen name | ||
// value: params (use undefined if accepts none) | ||
import { NavigatorScreenParams } from '@react-navigation/native'; | ||
import { NativeStackScreenProps } from '@react-navigation/native-stack'; | ||
|
||
export type RootStackParamList = { | ||
Tabs: NavigatorScreenParams<TabsParamList>; | ||
}; | ||
|
||
export type TabsParamList = { | ||
DashboardTab: NavigatorScreenParams<DashboardTabParamList>; | ||
SettingsTab: NavigatorScreenParams<SettingsTabParamList>; | ||
}; | ||
|
||
export type DashboardTabParamList = { | ||
Home: undefined; | ||
Information: { owner: string } | undefined; | ||
}; | ||
|
||
export type SettingsTabParamList = { | ||
Settings: undefined; | ||
}; | ||
|
||
/* ---------------------------------------------------------------- | ||
Derived types -- these should not need to be frequently modified | ||
-------------------------------------------------------------*/ | ||
export type TabName = keyof TabsParamList; | ||
export type RootRouteName = keyof RootStackParamList; | ||
export type AppRouteName = | ||
| keyof RootStackParamList | ||
| keyof DashboardTabParamList | ||
| keyof SettingsTabParamList; | ||
|
||
export type HomeScreenProp = NativeStackScreenProps< | ||
DashboardTabParamList, | ||
'Home' | ||
>; | ||
|
||
export type InformationScreenProp = NativeStackScreenProps< | ||
DashboardTabParamList, | ||
'Information' | ||
>; |
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
25 changes: 25 additions & 0 deletions
25
templates/boilerplate/src/screens/InformationScreen/InformationScreen.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,25 @@ | ||
import { useRoute } from '@react-navigation/native'; | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { InformationScreenProp } from 'src/navigators/navigatorTypes'; | ||
|
||
export default function InformationScreen() { | ||
const { params } = useRoute<InformationScreenProp['route']>(); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Information Screen</Text> | ||
{params && <Text>{params.owner}’s Profile</Text>} | ||
<StatusBar style="auto" /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: '#fff', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |
4 changes: 2 additions & 2 deletions
4
...ion/src/screens/HomeScreen/HomeScreen.tsx → ...screens/SettingsScreen/SettingsScreen.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
12 changes: 0 additions & 12 deletions
12
templates/reactNavigation/src/navigators/RootNavigator.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.