-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
161 lines (152 loc) · 5.86 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// App.tsx
import React, { useState, useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import Icon from "react-native-vector-icons/Ionicons";
import AllExercisesScreen from "./src/screens/AllExercisesScreen";
import AddExerciseScreen from "./src/screens/AddExerciseScreen";
import ExerciseHistoryScreen from "./src/screens/ExerciseHistoryScreen";
import SettingsScreen from "./src/screens/SettingsScreen";
import { ExerciseProvider } from "./src/contexts/ExerciseContext";
import { ThemeProvider, useTheme } from "./src/contexts/ThemeContext";
import { RootStackParamList } from "./src/types/navigation";
import { navigationTheme } from "./styles/globalStyles";
import TrainingIntervalScreen from "./src/screens/settings/TrainingIntervalScreen";
import DailyStepGoalScreen from "./src/screens/settings/DailyStepGoalScreen";
import WelcomeScreen from "./src/screens/WelcomeScreen";
import AsyncStorage from "@react-native-async-storage/async-storage";
import PlanPreviewScreen from "./src/screens/PlanPreviewScreen";
import StatsScreen from "./src/screens/StatsScreen";
import TodayScreen from "./src/screens/TodayScreen";
import WorkoutDetailScreen from "./src/screens/WorkoutDetailScreen";
import { HealthKitProvider } from "./src/contexts/HealthKitContext";
import OnboardingWizard from "./src/screens/OnboardingWizard";
const Stack = createStackNavigator<RootStackParamList>();
const Tab = createBottomTabNavigator();
const Home = () => (
<Tab.Navigator initialRouteName="AllExercises">
<Tab.Screen
name="Today"
component={TodayScreen}
options={{
title: "Today",
tabBarIcon: ({ color, size }) => <Icon name="calendar" color={color} size={size} />,
}}
/>
<Tab.Screen
name="AllExercises"
component={AllExercisesScreen}
options={{
title: "Exercises",
tabBarLabel: "Exercises",
tabBarIcon: ({ color, size }) => <Icon name="list" color={color} size={size} />,
}}
/>
<Tab.Screen
name="Stats"
component={StatsScreen}
options={{
title: "Training Statistics",
tabBarIcon: ({ color, size }) => (
<Icon name="stats-chart" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Settings"
component={SettingsScreen}
options={{
tabBarIcon: ({ color, size }) => (
<Icon name="settings-outline" color={color} size={size} />
),
}}
/>
</Tab.Navigator>
);
const AppContent = () => {
const { theme } = useTheme();
const [isFirstLaunch, setIsFirstLaunch] = useState<boolean | null>(null);
useEffect(() => {
checkIfFirstLaunch();
}, []);
const checkIfFirstLaunch = async () => {
try {
const alreadySetup = await AsyncStorage.getItem("alreadySetup");
if (alreadySetup === null || alreadySetup === "false") {
setIsFirstLaunch(true);
} else {
setIsFirstLaunch(false);
}
} catch (error) {
console.error("Error checking if first launch:", error);
setIsFirstLaunch(false);
}
};
if (isFirstLaunch === null) {
// Return a loading indicator or splash screen while checking
return null;
}
return (
<NavigationContainer theme={navigationTheme[theme]}>
<Stack.Navigator initialRouteName={isFirstLaunch ? "Welcome" : "Home"}>
<Stack.Screen
name="Welcome"
component={WelcomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen name="Home" component={Home} options={{ headerShown: false }} />
<Stack.Screen
name="AddExercise"
component={AddExerciseScreen}
options={{
presentation: "modal",
title: "Add Exercise",
}}
/>
<Stack.Screen
name="ExerciseHistory"
component={ExerciseHistoryScreen}
options={{ title: "Exercise History" }}
/>
<Stack.Screen
name="TrainingInterval"
component={TrainingIntervalScreen}
options={{ title: "Training Interval" }}
/>
<Stack.Screen
name="DailyStepGoal"
component={DailyStepGoalScreen}
options={{ title: "Daily Step Goal" }}
/>
<Stack.Screen
name="PlanPreview"
component={PlanPreviewScreen}
options={{ title: "Plan Preview" }}
/>
<Stack.Screen
name="WorkoutDetail"
component={WorkoutDetailScreen}
options={({ route }) => ({ title: route.params.workoutName })}
/>
<Stack.Screen
name="OnboardingWizard"
component={OnboardingWizard}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
const App = () => {
return (
<ThemeProvider>
<HealthKitProvider>
<ExerciseProvider>
<AppContent />
</ExerciseProvider>
</HealthKitProvider>
</ThemeProvider>
);
};
export default App;