From 9c2a86835f3637b89e3e3d006a80440ea29e7f4d Mon Sep 17 00:00:00 2001 From: dominictb Date: Fri, 26 Jul 2024 12:02:58 +0700 Subject: [PATCH] fix: force update status bar color --- .../CustomStatusBarAndBackground/index.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/CustomStatusBarAndBackground/index.tsx b/src/components/CustomStatusBarAndBackground/index.tsx index 356fbd3726a3..d21c0b3f9be0 100644 --- a/src/components/CustomStatusBarAndBackground/index.tsx +++ b/src/components/CustomStatusBarAndBackground/index.tsx @@ -95,20 +95,34 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack prevStatusBarBackgroundColor.current = statusBarBackgroundColor.current; statusBarBackgroundColor.current = currentScreenBackgroundColor; - if (currentScreenBackgroundColor !== theme.appBG || prevStatusBarBackgroundColor.current !== theme.appBG) { + const callUpdateStatusBarAppearance = () => { + updateStatusBarAppearance({statusBarStyle: newStatusBarStyle}); + setStatusBarStyle(newStatusBarStyle); + }; + + const callUpdateStatusBarBackgroundColor = () => { statusBarAnimation.value = 0; statusBarAnimation.value = withDelay(300, withTiming(1)); - } + }; // Don't update the status bar style if it's the same as the current one, to prevent flashing. // Force update if the root status bar is back on active or it won't overwirte the nested status bar style - if ((!didForceUpdateStatusBarRef.current && !prevIsRootStatusBarEnabled && isRootStatusBarEnabled) || newStatusBarStyle !== statusBarStyle) { - updateStatusBarAppearance({statusBarStyle: newStatusBarStyle}); - setStatusBarStyle(newStatusBarStyle); + if (!didForceUpdateStatusBarRef.current && !prevIsRootStatusBarEnabled && isRootStatusBarEnabled) { + callUpdateStatusBarAppearance(); + callUpdateStatusBarBackgroundColor(); if (!prevIsRootStatusBarEnabled && isRootStatusBarEnabled) { didForceUpdateStatusBarRef.current = true; } + return; + } + + if (newStatusBarStyle !== statusBarStyle) { + callUpdateStatusBarAppearance(); + } + + if (currentScreenBackgroundColor !== theme.appBG || prevStatusBarBackgroundColor.current !== theme.appBG) { + callUpdateStatusBarBackgroundColor(); } }, [prevIsRootStatusBarEnabled, isRootStatusBarEnabled, statusBarAnimation, statusBarStyle, theme.PAGE_THEMES, theme.appBG, theme.statusBarStyle],