Skip to content

Commit 740be51

Browse files
authored
Merge pull request #34409 from ishpaul777/fix/status-bar-color-on-mweb
Fix/status bar color on mweb
2 parents 8b770e5 + b669f7b commit 740be51

7 files changed

Lines changed: 37 additions & 17 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import {createContext} from 'react';
22

33
type CustomStatusBarAndBackgroundContextType = {
4-
isRootStatusBarDisabled: boolean;
5-
disableRootStatusBar: (isDisabled: boolean) => void;
4+
isRootStatusBarEnabled: boolean;
5+
setRootStatusBarEnabled: (isEnabled: boolean) => void;
66
};
77

8-
const CustomStatusBarAndBackgroundContext = createContext<CustomStatusBarAndBackgroundContextType>({isRootStatusBarDisabled: false, disableRootStatusBar: () => undefined});
8+
// Signin page has its seperate Statusbar and ThemeProvider, so when user is on the SignInPage we need to disable the root statusbar so there is no double status bar in component stack, first in Root and other in SignInPage
9+
const CustomStatusBarAndBackgroundContext = createContext<CustomStatusBarAndBackgroundContextType>({isRootStatusBarEnabled: true, setRootStatusBarEnabled: () => undefined});
910

1011
export default CustomStatusBarAndBackgroundContext;
1112
export {type CustomStatusBarAndBackgroundContextType};

src/components/CustomStatusBarAndBackground/CustomStatusBarAndBackgroundContextProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import React, {useMemo, useState} from 'react';
22
import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackgroundContext';
33

44
function CustomStatusBarAndBackgroundContextProvider({children}: React.PropsWithChildren) {
5-
const [isRootStatusBarDisabled, disableRootStatusBar] = useState(false);
5+
const [isRootStatusBarEnabled, setRootStatusBarEnabled] = useState(true);
66
const value = useMemo(
77
() => ({
8-
isRootStatusBarDisabled,
9-
disableRootStatusBar,
8+
isRootStatusBarEnabled,
9+
setRootStatusBarEnabled,
1010
}),
11-
[isRootStatusBarDisabled],
11+
[isRootStatusBarEnabled],
1212
);
1313

1414
return <CustomStatusBarAndBackgroundContext.Provider value={value}>{children}</CustomStatusBarAndBackgroundContext.Provider>;

src/components/CustomStatusBarAndBackground/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,29 @@ type CustomStatusBarAndBackgroundProps = {
1414
};
1515

1616
function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBackgroundProps) {
17-
const {isRootStatusBarDisabled, disableRootStatusBar} = useContext(CustomStatusBarAndBackgroundContext);
17+
const {isRootStatusBarEnabled, setRootStatusBarEnabled} = useContext(CustomStatusBarAndBackgroundContext);
1818
const theme = useTheme();
1919
const [statusBarStyle, setStatusBarStyle] = useState(theme.statusBarStyle);
2020

21-
const isDisabled = !isNested && isRootStatusBarDisabled;
21+
const isDisabled = !isNested && !isRootStatusBarEnabled;
2222

2323
// Disable the root status bar when a nested status bar is rendered
2424
useEffect(() => {
2525
if (isNested) {
26-
disableRootStatusBar(true);
26+
setRootStatusBarEnabled(false);
2727
}
2828

2929
return () => {
3030
if (!isNested) {
3131
return;
3232
}
33-
disableRootStatusBar(false);
33+
setRootStatusBarEnabled(true);
3434
};
35-
}, [disableRootStatusBar, isNested]);
35+
}, [isNested, setRootStatusBarEnabled]);
3636

37-
const prevStatusBarBackgroundColor = useRef(theme.appBG);
38-
const statusBarBackgroundColor = useRef(theme.appBG);
37+
// The prev and current status bar background color refs are initialized with the splash screen background color so the status bar color is changed from the splash screen color to the expected color atleast once on first render - https://github.com/Expensify/App/issues/34154
38+
const prevStatusBarBackgroundColor = useRef(theme.splashBG);
39+
const statusBarBackgroundColor = useRef(theme.splashBG);
3940
const statusBarAnimation = useSharedValue(0);
4041

4142
useAnimatedReaction(
@@ -57,7 +58,9 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack
5758
// This callback is triggered everytime the route changes or the theme changes
5859
const updateStatusBarStyle = useCallback(
5960
(listenerId?: number) => {
60-
// Check if this function is either called through the current navigation listener or the general useEffect which listens for theme changes.
61+
// Check if this function is either called through the current navigation listener
62+
// react-navigation library has a bug internally, where it can't keep track of the listeners, therefore, sometimes when the useEffect would re-render and we run navigationRef.removeListener the listener isn't removed and we end up with two or more listeners.
63+
// https://github.com/Expensify/App/issues/34154#issuecomment-1898519399
6164
if (listenerId !== undefined && listenerId !== listenerCount.current) {
6265
return;
6366
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import colors from '@styles/theme/colors';
2+
3+
function getSplashBackgroundColor() {
4+
return colors.green400;
5+
}
6+
7+
export default getSplashBackgroundColor;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import colors from '@styles/theme/colors';
2+
3+
function getSplashBackgroundColor() {
4+
return colors.productDark100;
5+
}
6+
7+
export default getSplashBackgroundColor;

src/styles/theme/themes/dark.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import getSplashBackgroundColor from '@libs/getSplashBackgroundColor';
12
import colors from '@styles/theme/colors';
23
import type {ThemeColors} from '@styles/theme/types';
34
import CONST from '@src/CONST';
@@ -6,7 +7,7 @@ import SCREENS from '@src/SCREENS';
67
const darkTheme = {
78
// Figma keys
89
appBG: colors.productDark100,
9-
splashBG: colors.green400,
10+
splashBG: getSplashBackgroundColor(),
1011
highlightBG: colors.productDark200,
1112
border: colors.productDark400,
1213
borderLighter: colors.productDark400,

src/styles/theme/themes/light.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import getSplashBackgroundColor from '@libs/getSplashBackgroundColor';
12
import colors from '@styles/theme/colors';
23
import type {ThemeColors} from '@styles/theme/types';
34
import CONST from '@src/CONST';
@@ -6,7 +7,7 @@ import SCREENS from '@src/SCREENS';
67
const lightTheme = {
78
// Figma keys
89
appBG: colors.productLight100,
9-
splashBG: colors.green400,
10+
splashBG: getSplashBackgroundColor(),
1011
highlightBG: colors.productLight200,
1112
border: colors.productLight400,
1213
borderLighter: colors.productLight400,

0 commit comments

Comments
 (0)