Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/status bar color on mweb #34409

Merged
merged 31 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c144200
fixes the issue
ishpaul777 Jan 11, 2024
d7ad870
fixed blinking of the status bar
ishpaul777 Jan 11, 2024
52d3128
fixes the issue
ishpaul777 Jan 12, 2024
9d4e5b0
prettier diffs
ishpaul777 Jan 12, 2024
731f70d
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Jan 12, 2024
97755dd
fixes the issue v2
ishpaul777 Jan 14, 2024
073a480
fixes android dark mode issue
ishpaul777 Jan 18, 2024
5f11157
prettier fix
ishpaul777 Jan 18, 2024
d19a95d
fix prettier diffs
ishpaul777 Jan 18, 2024
d9d6cc8
clean up
ishpaul777 Jan 18, 2024
0d15185
fixes color naming
ishpaul777 Jan 23, 2024
80deeaf
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Jan 23, 2024
2f9f73b
added comments for the changes
ishpaul777 Jan 23, 2024
76ce335
added comment for when status bar context is required
ishpaul777 Jan 23, 2024
87d6656
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Jan 25, 2024
233fba9
added requested changes
ishpaul777 Jan 25, 2024
0e790b8
fixed statusbar content style
ishpaul777 Jan 25, 2024
cdf6eb9
prettier diffs
ishpaul777 Jan 25, 2024
ea47400
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Jan 29, 2024
fd7aca0
listen to theme changes
ishpaul777 Jan 29, 2024
cde910b
include comment for useeffect
ishpaul777 Jan 29, 2024
8ca38d0
Update src/components/CustomStatusBarAndBackground/index.tsx
ishpaul777 Jan 29, 2024
321b278
remove urelated changes
ishpaul777 Jan 29, 2024
4508091
rectify comment
ishpaul777 Jan 29, 2024
91ad613
remove unnecessary useEffect dependency
ishpaul777 Jan 29, 2024
cb3eb19
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Feb 11, 2024
d041b91
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Feb 17, 2024
0432658
refactor after merge
ishpaul777 Feb 17, 2024
3ea154d
prettier
ishpaul777 Feb 17, 2024
49f5ddd
Merge branch 'Expensify:main' into fix/status-bar-color-on-mweb
ishpaul777 Feb 26, 2024
b669f7b
used platform files for platform specfic code
ishpaul777 Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {createContext} from 'react';

type CustomStatusBarAndBackgroundContextType = {
isRootStatusBarDisabled: boolean;
disableRootStatusBar: (isDisabled: boolean) => void;
isRootStatusBarEnabled: boolean;
setRootStatusBarEnabled: (isEnabled: boolean) => void;
};

const CustomStatusBarAndBackgroundContext = createContext<CustomStatusBarAndBackgroundContextType>({isRootStatusBarDisabled: false, disableRootStatusBar: () => undefined});
// 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
const CustomStatusBarAndBackgroundContext = createContext<CustomStatusBarAndBackgroundContextType>({isRootStatusBarEnabled: true, setRootStatusBarEnabled: () => undefined});

export default CustomStatusBarAndBackgroundContext;
export {type CustomStatusBarAndBackgroundContextType};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React, {useMemo, useState} from 'react';
import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackgroundContext';

function CustomStatusBarAndBackgroundContextProvider({children}: React.PropsWithChildren) {
const [isRootStatusBarDisabled, disableRootStatusBar] = useState(false);
const [isRootStatusBarEnabled, setRootStatusBarEnabled] = useState(true);
const value = useMemo(
() => ({
isRootStatusBarDisabled,
disableRootStatusBar,
isRootStatusBarEnabled,
setRootStatusBarEnabled,
}),
[isRootStatusBarDisabled],
[isRootStatusBarEnabled],
);

return <CustomStatusBarAndBackgroundContext.Provider value={value}>{children}</CustomStatusBarAndBackgroundContext.Provider>;
Expand Down
22 changes: 14 additions & 8 deletions src/components/CustomStatusBarAndBackground/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, {useCallback, useContext, useEffect, useRef, useState} from 'react';
import {interpolateColor, runOnJS, useAnimatedReaction, useSharedValue, withDelay, withTiming} from 'react-native-reanimated';
import useTheme from '@hooks/useTheme';
import getPlatform from '@libs/getPlatform';
import {navigationRef} from '@libs/Navigation/Navigation';
import StatusBar from '@libs/StatusBar';
import CONST from '@src/CONST';
import CustomStatusBarAndBackgroundContext from './CustomStatusBarAndBackgroundContext';
import updateGlobalBackgroundColor from './updateGlobalBackgroundColor';
import updateStatusBarAppearance from './updateStatusBarAppearance';
Expand All @@ -14,28 +16,30 @@ type CustomStatusBarAndBackgroundProps = {
};

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

const isDisabled = !isNested && isRootStatusBarDisabled;
const isDisabled = !isNested && !isRootStatusBarEnabled;

// Disable the root status bar when a nested status bar is rendered
useEffect(() => {
if (isNested) {
disableRootStatusBar(true);
setRootStatusBarEnabled(false);
}

return () => {
if (!isNested) {
return;
}
disableRootStatusBar(false);
setRootStatusBarEnabled(true);
};
}, [disableRootStatusBar, isNested]);
}, [isNested, setRootStatusBarEnabled]);

const prevStatusBarBackgroundColor = useRef(theme.appBG);
const statusBarBackgroundColor = useRef(theme.appBG);
// 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
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
const initialBgColor = getPlatform() === CONST.PLATFORM.WEB ? theme.splashBGWeb : theme.splashBG;
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious about the use of getPlatform() here. We normally use platform files, is it allowed here? I see that getPlatform is used at a couple of places in the app.

cc: @roryabraham

const prevStatusBarBackgroundColor = useRef(initialBgColor);
const statusBarBackgroundColor = useRef(initialBgColor);
const statusBarAnimation = useSharedValue(0);

useAnimatedReaction(
Expand All @@ -57,7 +61,9 @@ function CustomStatusBarAndBackground({isNested = false}: CustomStatusBarAndBack
// This callback is triggered everytime the route changes or the theme changes
const updateStatusBarStyle = useCallback(
(listenerId?: number) => {
// Check if this function is either called through the current navigation listener or the general useEffect which listens for theme changes.
// Check if this function is either called through the current navigation listener
// 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.
// https://github.com/Expensify/App/issues/34154#issuecomment-1898519399
if (listenerId !== undefined && listenerId !== listenerCount.current) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const darkTheme = {
placeholderText: colors.productDark700,
heroCard: colors.blue400,
uploadPreviewActivityIndicator: colors.productDark200,
splashBGWeb: colors.productDark100,
ishpaul777 marked this conversation as resolved.
Show resolved Hide resolved
dropUIBG: 'rgba(6,27,9,0.92)',
receiptDropUIBG: 'rgba(3, 212, 124, 0.84)',
checkBox: colors.green400,
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const lightTheme = {
offline: colors.productLight700,
modalBackground: colors.productLight100,
cardBG: colors.productLight200,
splashBGWeb: colors.productDark100,
cardBorder: colors.productLight200,
spinner: colors.productLight800,
unreadIndicator: colors.green400,
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ThemeColors = {
mentionBG: Color;
ourMentionText: Color;
ourMentionBG: Color;
splashBGWeb: Color;
tooltipSupportingText: Color;
tooltipPrimaryText: Color;
skeletonLHNIn: Color;
Expand Down
Loading