From ba0db375eff28bb7ab8ff7200c321672c9361df3 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Wed, 9 Nov 2022 21:55:34 +0500 Subject: [PATCH] fixed iOS reload flash on app resume --- src/screens/application/hook/useInitApplication.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/screens/application/hook/useInitApplication.tsx b/src/screens/application/hook/useInitApplication.tsx index ff898652a..dcaf90957 100644 --- a/src/screens/application/hook/useInitApplication.tsx +++ b/src/screens/application/hook/useInitApplication.tsx @@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react'; import Orientation, { useDeviceOrientationChange } from 'react-native-orientation-locker'; import { isLandscape } from 'react-native-device-info'; import EStyleSheet from 'react-native-extended-stylesheet'; -import { AppState, NativeEventSubscription, useColorScheme } from 'react-native'; +import { Appearance, AppState, NativeEventSubscription, useColorScheme } from 'react-native'; import { useAppDispatch, useAppSelector } from '../../../hooks'; import { setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction'; import { orientations } from '../../../redux/constants/orientationsConstants'; @@ -52,7 +52,13 @@ export const useInitApplication = () => { useEffect(() => { if (THEME_OPTIONS[colorTheme].value === null) { - dispatch(setIsDarkTheme(systemColorScheme === 'dark')); + // workaround to avoid hook callback glitch on iOS causing momentary theme flash + setTimeout(() => { + const sysDarkTheme = Appearance.getColorScheme() === 'dark'; + if (sysDarkTheme !== isDarkTheme) { + dispatch(setIsDarkTheme(sysDarkTheme)); + } + }, 200); } }, [systemColorScheme]);