Skip to content

Commit

Permalink
Created app.navigation example to show how you can set thing up to ju…
Browse files Browse the repository at this point in the history
…mp from page/screen to screen

  1. Create example file from app.navigation.js
  2. trim it and add temp screens
  3. yarn add @react-navigation/stack
  4. Use stack navigation to move around screen
  • Loading branch information
EfrainAD committed Dec 14, 2023
1 parent 204926b commit 30ed9c5
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 139 deletions.
164 changes: 25 additions & 139 deletions src/infrastructure/navigation/app.navigation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { Button, Text, View } from 'react-native'
import { Text, View } from 'react-native'
import { SafeArea } from './../../components/utilities/safeArea.component'
import { Ionicons } from '@expo/vector-icons'
import { FontAwesome5 } from '@expo/vector-icons'
Expand Down Expand Up @@ -30,7 +29,6 @@ import SecurityScreen from '../../screens/account/security.screen'
import ChategoryScreen from '../../screens/trophy/userTrophy.screen'

const Tab = createBottomTabNavigator()
const Stack = createStackNavigator()

const TAB_ICONS = {
Stats: (size, color) => (
Expand All @@ -48,139 +46,28 @@ const TAB_ICONS = {
}

// Temps, until they are actoually name..
function WorkMain({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work Main!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work1({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work One!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work2({ navigation }) {
return (
<SafeArea
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work2!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work3({ navigation }) {
return (
<SafeArea
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work3!</Text>
<Button
title="Go to MAIN Screen"
onPress={() => navigation.navigate('WorkMain')}
/>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function WorkStack() {
return (
<Stack.Navigator>
<Stack.Screen name="WorkMain" component={WorkMain} />
<Stack.Screen name="Work1" component={Work1} />
<Stack.Screen name="Work2" component={Work2} />
<Stack.Screen name="Work3" component={Work3} />
</Stack.Navigator>
)
}
// AccMain
function AccMain({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work Main!</Text>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
</SafeArea>
)
}
function AccStack() {
return (
<Stack.Navigator>
<Stack.Screen name="AccMain" component={AccMain} />
</Stack.Navigator>
)
}

// In USE
// function StatsScreen() {
// return (
// <SafeArea
// style={{
// flex: 1,
// justifyContent: 'center',
// alignItems: 'center',
// }}
// >
// <Text style={{ fontSize: theme.fontSizes.h2 }}>Stats!</Text>
// </SafeArea>
// )
// }
// function WorkoutsScreen() {
// return (
// <SafeArea
// style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
// >
// <Text style={{ fontSize: theme.fontSizes.h2 }}>Workouts!</Text>
// </SafeArea>
// )
// }
function DashboardScreen() {
return (
<>
Expand All @@ -206,11 +93,10 @@ export const AppNavigator = () => {
return (
<NavigationContainer>
<Tab.Navigator screenOptions={screenOptions}>
<Tab.Screen name="Stats" component={WorkStack} />
{/* <Tab.Screen name="Stats" component={StatsScreen} /> */}
<Tab.Screen name="Stats" component={StatsScreen} />
<Tab.Screen name="Workouts" component={AddWorkoutExample} />
<Tab.Screen name="Dashboard" component={DashboardScreen} />
<Tab.Screen name="Account" component={AccStack} />
<Tab.Screen name="Account" component={AccountScreen} />
</Tab.Navigator>
</NavigationContainer>
)
Expand Down
189 changes: 189 additions & 0 deletions src/infrastructure/navigation/appExample.navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
import { Button, Text } from 'react-native'
import { SafeArea } from './../../components/utilities/safeArea.component'
import { Ionicons } from '@expo/vector-icons'
import { FontAwesome5 } from '@expo/vector-icons'
import { theme } from './../theme'

import DashboardMain from '../../screens/dashboard/DashboardMain'
import AddWorkoutExample from '../../services/api/addWorkoutExample.screen'

// Navigation Components
const Tab = createBottomTabNavigator()
const Stack = createStackNavigator()

const TAB_ICONS = {
Stats: (size, color) => (
<Ionicons name="stats-chart" size={size} color={color} />
),
Workouts: (size, color) => (
<FontAwesome5 name="dumbbell" size={size} color={color} />
),
Dashboard: (size, color) => (
<Ionicons name="speedometer" size={size} color={color} />
),
Account: (size, color) => (
<Ionicons name="person" size={size} color={color} />
),
}

// Screens for Work
function WorkMain({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work Main!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work1({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work One!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work2({ navigation }) {
return (
<SafeArea
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work2!</Text>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
function Work3({ navigation }) {
return (
<SafeArea
style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work3!</Text>
<Button
title="Go to MAIN Screen"
onPress={() => navigation.navigate('WorkMain')}
/>
<Button
title="Go to Work1 Screen"
onPress={() => navigation.navigate('Work1')}
/>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
<Button
title="Go to Work3 Screen"
onPress={() => navigation.navigate('Work3')}
/>
</SafeArea>
)
}
// Screens for Acc
function AccMain({ navigation }) {
return (
<SafeArea
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text style={{ fontSize: theme.fontSizes.h2 }}>Work Main!</Text>
<Button
title="Go to Work2 Screen"
onPress={() => navigation.navigate('Work2')}
/>
</SafeArea>
)
}

// Navigation Stacks
function WorkStack() {
return (
<Stack.Navigator>
<Stack.Screen name="WorkMain" component={WorkMain} />
<Stack.Screen name="Work1" component={Work1} />
<Stack.Screen name="Work2" component={Work2} />
<Stack.Screen name="Work3" component={Work3} />
</Stack.Navigator>
)
}
function AccStack() {
return (
<Stack.Navigator>
<Stack.Screen name="AccMain" component={AccMain} />
</Stack.Navigator>
)
}

const screenOptions = ({ route }) => ({
tabBarIcon: ({ color, size }) => {
const iconRenderer = TAB_ICONS[route.name]

return iconRenderer(size, color)
},
tabBarActiveTintColor: theme.colors.ui.primary,
tabBarInactiveTintColor: theme.colors.ui.secondary,
headerShown: false,
})

export const AppNavigator = () => {
return (
<NavigationContainer>
<Tab.Navigator screenOptions={screenOptions}>
<Tab.Screen name="Stats" component={WorkStack} />
<Tab.Screen name="Workouts" component={AddWorkoutExample} />
<Tab.Screen name="Dashboard" component={DashboardMain} />
<Tab.Screen name="Account" component={AccStack} />
</Tab.Navigator>
</NavigationContainer>
)
}

0 comments on commit 30ed9c5

Please sign in to comment.