From 03690e1798b4ba18d1648b72233653c2730861a3 Mon Sep 17 00:00:00 2001 From: benguedj <71835422+benguedj@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:15:32 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Corrige=20l'erreur=20Sent?= =?UTF-8?q?ry=20:=20Current=20activity=20not=20found=20(#1718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #1254 --- front/App.tsx | 17 ++++++++++++++--- front/src/hooks/useCachedResources.ts | 4 ---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/front/App.tsx b/front/App.tsx index 927382dfe..877f7c9c3 100644 --- a/front/App.tsx +++ b/front/App.tsx @@ -1,4 +1,5 @@ import * as Font from "expo-font"; +import * as SplashScreen from "expo-splash-screen"; import { StatusBar } from "expo-status-bar"; import type { FC } from "react"; import * as React from "react"; @@ -30,6 +31,9 @@ import { TrackerUtils, } from "./src/utils"; +// Keep the splash screen visible while we fetch resources +void SplashScreen.preventAutoHideAsync(); + setNotificationHandler(); initLocales(); initMonitoring(); @@ -138,17 +142,24 @@ const MainAppContainer: FC = () => { void init(); // Permet de détecter lorsque l'app change d'état ('active' | 'background' | 'inactive' | 'unknown' | 'extension') - AppState.addEventListener("change", handleAppStateChange); + const subscription = AppState.addEventListener( + "change", + handleAppStateChange + ); return () => { - AppState.removeEventListener("change", handleAppStateChange); + subscription.remove(); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useEffect(() => { if (isLoadingComplete && fontsLoaded && appCounterIsLoaded) { - setScreenCanBeDisplayed(true); + const hideSplashScreen = async () => { + await SplashScreen.hideAsync(); + setScreenCanBeDisplayed(true); + }; + void hideSplashScreen(); } }, [isLoadingComplete, fontsLoaded, appCounterIsLoaded]); diff --git a/front/src/hooks/useCachedResources.ts b/front/src/hooks/useCachedResources.ts index 4eacbd055..7474e9065 100644 --- a/front/src/hooks/useCachedResources.ts +++ b/front/src/hooks/useCachedResources.ts @@ -1,6 +1,5 @@ import { Ionicons } from "@expo/vector-icons"; import * as Font from "expo-font"; -import * as SplashScreen from "expo-splash-screen"; import { useEffect, useState } from "react"; const useCachedResources = (): boolean => { @@ -10,8 +9,6 @@ const useCachedResources = (): boolean => { useEffect(() => { async function loadResourcesAndDataAsync() { try { - void SplashScreen.preventAutoHideAsync(); - // Load fonts await Font.loadAsync({ ...Ionicons.font, @@ -34,7 +31,6 @@ const useCachedResources = (): boolean => { console.warn(error); } finally { setLoadingComplete(true); - void SplashScreen.hideAsync(); } }