From de89481cb3a68f051ba1bdacbf5dfc991cf4f93a Mon Sep 17 00:00:00 2001 From: G Date: Mon, 9 Sep 2024 17:17:33 +0000 Subject: [PATCH] handling logic for splash screen in auth context. memo this component for caching --- src/navigations/AppMainStackNavigator.tsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/navigations/AppMainStackNavigator.tsx b/src/navigations/AppMainStackNavigator.tsx index 5416642..c767f93 100644 --- a/src/navigations/AppMainStackNavigator.tsx +++ b/src/navigations/AppMainStackNavigator.tsx @@ -5,7 +5,7 @@ import HomeUserNotLoggedIn from "@screens/HomeUserNotLoggedIn"; import PaymentResultScreen from "@screens/PaymentResultScreen"; import UserLoginScreen from "@screens/UserLoginScreen"; import WaveQrCodePaymentScreen from "@screens/WaveQrCodePaymentScreen"; -import * as SplashScreen from "expo-splash-screen"; +import { memo } from "react"; import { AppBottomTabsNavigator } from "./AppBottomTabsNavigator"; import type { ImainStackNavigator } from "./Types"; @@ -13,20 +13,14 @@ const Stack = createNativeStackNavigator(); const log = LOG.extend("AppMainStackNavigator"); -SplashScreen.preventAutoHideAsync(); +interface IappMainStackNavigatorProps { + isAuthenticated: boolean; +} -const AppMainStackNavigator = () => { - const { isAuthenticated, isAuthenticating } = useUserAuthenticationContext(); - - if (isAuthenticating) { - log.info("isAuthenticating"); - return null; - } - (async () => { - await SplashScreen.hideAsync(); - })(); - if (!isAuthenticating && !isAuthenticated) { +const AppMainStackNavigator: React.FC = ({ isAuthenticated }) => { + if (!isAuthenticated) { log.info("Navigating to UserLoginScreen"); + return ( { ); }; -export default AppMainStackNavigator; +export default memo(AppMainStackNavigator); + +export const AppMainStackNavigatorAuthWrapper = () => { + const { isAuthenticated } = useUserAuthenticationContext(); + return ; +}; -- libgit2 0.27.1