diff --git a/src/hooks/useSignedUser.ts b/src/hooks/useSignedUser.ts index 8407f86..8e6f5ef 100644 --- a/src/hooks/useSignedUser.ts +++ b/src/hooks/useSignedUser.ts @@ -3,13 +3,22 @@ import SignedUser from "../types/user" import { getUserAsyncStorage } from "../services/asyncStorageUser"; export const useSignedUser = () => { - const [user, setUser] = useState(null); + const [userAndLoading, setUserAndLoading] = useState<{ + signedUser: SignedUser | null, + isLoading: boolean + }>({ + signedUser: null, + isLoading: true + }); const setData = async () => { const _user = await getUserAsyncStorage(); - setUser(_user); + setUserAndLoading({ + signedUser: _user, + isLoading: false + }); } useEffect(() => { setData(); }, []); - return user; + return userAndLoading; } \ No newline at end of file diff --git a/src/navigation/bottomTabBar/bottomTabBar.tsx b/src/navigation/bottomTabBar/bottomTabBar.tsx index 5ba1a74..33990c8 100644 --- a/src/navigation/bottomTabBar/bottomTabBar.tsx +++ b/src/navigation/bottomTabBar/bottomTabBar.tsx @@ -1,5 +1,5 @@ import { StyleSheet, Text, View, TouchableOpacity } from 'react-native' -import { createBottomTabNavigator } from '@react-navigation/bottom-tabs' +import { BottomTabBarButtonProps, createBottomTabNavigator } from '@react-navigation/bottom-tabs' import React from 'react' import { useIsDarkMode } from '../../hooks/useIsDarkMode'; import WishListScreen from '../../screens/wishList'; @@ -9,6 +9,9 @@ import { COLORS, SIZES } from '../../constants'; import Icon from 'react-native-vector-icons/FontAwesome'; const TabBar = createBottomTabNavigator(); +const renderBottomBtn = ({ children , onPress }: BottomTabBarButtonProps) => ( + {children} +) const MainTabBar = () => { const isDark = useIsDarkMode(); return ( @@ -17,23 +20,26 @@ const MainTabBar = () => { headerShown: false, tabBarStyle: styles.bottomTabBarCustomStyle, tabBarActiveTintColor: COLORS.white, - tabBarInactiveTintColor: COLORS.socendry, + tabBarInactiveTintColor: COLORS.tintColor, tabBarShowLabel: false } }}> ( { tabBarIcon: ({ focused, color, size }) => (), + tabBarButton: renderBottomBtn } )} /> ( { - tabBarIcon: ({ focused, color, size }) => () + tabBarIcon: ({ focused, color, size }) => (), + tabBarButton: renderBottomBtn } )} /> ( { - tabBarIcon: ({ focused, color, size }) => () + tabBarIcon: ({ focused, color, size }) => (), + tabBarButton: renderBottomBtn } )} /> @@ -44,7 +50,7 @@ export default MainTabBar const styles = StyleSheet.create({ bottomTabBarCustomStyle: { - borderRadius: SIZES.radius, + borderRadius: SIZES.radius2, padding: 5 * SIZES.padding2, justifyContent: "center", alignItems: "center", @@ -54,6 +60,13 @@ const styles = StyleSheet.create({ left: 0.05 * SIZES.fullScreenWidth, bottom: 30, backgroundColor: COLORS.primary, - elevation : 0 + elevation: 0 + }, + btmBtn: { + flex: 1, + backgroundColor: COLORS.transparent, + height : 25, + bottom: 30, + alignSelf : "center" } }) \ No newline at end of file diff --git a/src/navigation/index.tsx b/src/navigation/index.tsx index 1e59065..84f8f7f 100644 --- a/src/navigation/index.tsx +++ b/src/navigation/index.tsx @@ -5,17 +5,19 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack' import LoginScreen from '../screens/loginScreen'; import MainTabBar from './bottomTabBar/bottomTabBar'; import { useSignedUser } from '../hooks/useSignedUser'; +import LoadingMainScreenMyScreen from '../screens/loadingScreen'; const StackNavigation = createNativeStackNavigator(); export default function Navigation() { const signedUser = useSignedUser(); return ( - { + { return { headerShown: false } }}> + diff --git a/src/screens/loadingScreen/index.tsx b/src/screens/loadingScreen/index.tsx new file mode 100644 index 0000000..1018f11 --- /dev/null +++ b/src/screens/loadingScreen/index.tsx @@ -0,0 +1,40 @@ +import { StyleSheet, Text, View } from 'react-native' +import React, { useEffect, useRef } from 'react' +import { ActivityIndicator } from "@react-native-material/core"; +import { COLORS } from '../../constants'; +import { useIsDarkMode } from '../../hooks/useIsDarkMode'; +import { useSignedUser } from '../../hooks/useSignedUser'; +import { useNavigation } from '@react-navigation/native'; + +const LoadingMainScreenMyScreen = () => { + const isDark = useIsDarkMode(); + const userAndLoading = useSignedUser(); + // ref to use side effects on new values only + const renderRef = useRef(0); + // navigation + const navigation = useNavigation(); + useEffect(() => { + if (renderRef.current === 0) renderRef.current += 1; + else { + if (userAndLoading.signedUser) navigation.navigate("root" as never); + else navigation.navigate("login" as never); + } + }, [ + userAndLoading.isLoading + ]) + return ( + + + + ) +} + +export default LoadingMainScreenMyScreen + +const styles = StyleSheet.create({ + screen: { + flex: 1, + justifyContent: "center", + alignItems: "center" + }, +}) \ No newline at end of file