chore: Delay splash screen hide until auth and theme stores are hydrated
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
import {useAuth} from "@/src/stores/authStore";
|
||||
import {useThemeStore} from "@/src/stores/themeStore";
|
||||
import NotAuthenticated from "@/src/components/NotAuthenticated";
|
||||
import LoadingScreen from "@/src/components/LoadingScreen";
|
||||
import * as SplashScreen from 'expo-splash-screen';
|
||||
|
||||
const AuthenticatedWrapper: React.FC<{ children: React.ReactNode }> = ({children}) => {
|
||||
const {isAuthenticated, loading, authenticatedUser, isHydrated} = useAuth();
|
||||
const {isAuthenticated, loading, authenticatedUser, isHydrated: authHydrated} = useAuth();
|
||||
const {isHydrated: themeHydrated} = useThemeStore();
|
||||
|
||||
if (!isHydrated || loading) {
|
||||
// Verstecke den Splash Screen erst wenn beide Stores hydratiert sind
|
||||
useEffect(() => {
|
||||
if (authHydrated && themeHydrated) {
|
||||
SplashScreen.hideAsync().catch(() => {});
|
||||
}
|
||||
}, [authHydrated, themeHydrated]);
|
||||
|
||||
// Zeige nichts (Splash Screen bleibt) bis beide Stores hydratiert sind
|
||||
if (!authHydrated || !themeHydrated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Zeige LoadingScreen während Auth Status geprüft wird
|
||||
if (loading) {
|
||||
return <LoadingScreen />;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {useColorScheme} from "nativewind";
|
||||
import LoadingScreen from "@/src/components/LoadingScreen";
|
||||
import * as SplashScreen from 'expo-splash-screen';
|
||||
|
||||
SplashScreen.hideAsync().catch(() => {});
|
||||
SplashScreen.preventAutoHideAsync().catch(() => {});
|
||||
|
||||
export const ThemeProvider = ({children}: { children: ReactNode }) => {
|
||||
const { theme, isDark, isHydrated } = useThemeStore();
|
||||
|
||||
Reference in New Issue
Block a user