forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
539 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"ignoredFiles": [ | ||
"assets/images/empty-state_background-fade.png" // Caused an issue with colour gradients, https://github.com/Expensify/App/issues/30499 | ||
"assets/images/empty-state_background-fade-dark.png", // Caused an issue with colour gradients, https://github.com/Expensify/App/issues/30499 | ||
"assets/images/empty-state_background-fade-light.png" | ||
], | ||
"aggressiveCompression": "false" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function ColorSchemeWrapper({children}: React.PropsWithChildren) { | ||
return children; | ||
} | ||
|
||
export default ColorSchemeWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import useTheme from '@styles/themes/useTheme'; | ||
import useThemeStyles from '@styles/useThemeStyles'; | ||
|
||
function ColorSchemeWrapper({children}: React.PropsWithChildren): React.ReactElement { | ||
const theme = useTheme(); | ||
const themeStyles = useThemeStyles(); | ||
|
||
return <View style={[themeStyles.flex1, themeStyles.colorSchemeStyle(theme.colorScheme)]}>{children}</View>; | ||
} | ||
|
||
export default ColorSchemeWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {createContext} from 'react'; | ||
|
||
type CustomStatusBarContextType = { | ||
isRootStatusBarDisabled: boolean; | ||
disableRootStatusBar: (isDisabled: boolean) => void; | ||
}; | ||
|
||
const CustomStatusBarContext = createContext<CustomStatusBarContextType>({isRootStatusBarDisabled: false, disableRootStatusBar: () => undefined}); | ||
|
||
export default CustomStatusBarContext; | ||
export {type CustomStatusBarContextType}; |
17 changes: 17 additions & 0 deletions
17
src/components/CustomStatusBar/CustomStatusBarContextProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {useMemo, useState} from 'react'; | ||
import CustomStatusBarContext from './CustomStatusBarContext'; | ||
|
||
function CustomStatusBarContextProvider({children}: React.PropsWithChildren) { | ||
const [isRootStatusBarDisabled, disableRootStatusBar] = useState(false); | ||
const value = useMemo( | ||
() => ({ | ||
isRootStatusBarDisabled, | ||
disableRootStatusBar, | ||
}), | ||
[isRootStatusBarDisabled], | ||
); | ||
|
||
return <CustomStatusBarContext.Provider value={value}>{children}</CustomStatusBarContext.Provider>; | ||
} | ||
|
||
export default CustomStatusBarContextProvider; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,91 @@ | ||
import React, {useEffect} from 'react'; | ||
import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; | ||
import {EventListenerCallback, NavigationContainerEventMap} from '@react-navigation/native'; | ||
import PropTypes from 'prop-types'; | ||
import React, {useCallback, useContext, useEffect} from 'react'; | ||
import {navigationRef} from '@libs/Navigation/Navigation'; | ||
import StatusBar from '@libs/StatusBar'; | ||
import useTheme from '@styles/themes/useTheme'; | ||
import type CustomStatusBarType from './types'; | ||
import CustomStatusBarContext from './CustomStatusBarContext'; | ||
|
||
type CustomStatusBarProps = { | ||
isNested: boolean; | ||
}; | ||
|
||
const propTypes = { | ||
/** Whether the CustomStatusBar is nested within another CustomStatusBar. | ||
* A nested CustomStatusBar will disable the "root" CustomStatusBar. */ | ||
isNested: PropTypes.bool, | ||
}; | ||
|
||
type CustomStatusBarType = { | ||
(props: CustomStatusBarProps): React.ReactNode; | ||
displayName: string; | ||
propTypes: typeof propTypes; | ||
}; | ||
|
||
// eslint-disable-next-line react/function-component-definition | ||
const CustomStatusBar: CustomStatusBarType = () => { | ||
const CustomStatusBar: CustomStatusBarType = ({isNested = false}) => { | ||
const {isRootStatusBarDisabled, disableRootStatusBar} = useContext(CustomStatusBarContext); | ||
const theme = useTheme(); | ||
|
||
const isDisabled = !isNested && isRootStatusBarDisabled; | ||
|
||
useEffect(() => { | ||
Navigation.isNavigationReady().then(() => { | ||
// Set the status bar colour depending on the current route. | ||
// If we don't have any colour defined for a route, fall back to | ||
// appBG color. | ||
const currentRoute = navigationRef.getCurrentRoute(); | ||
let currentScreenBackgroundColor = theme.appBG; | ||
if (currentRoute && 'name' in currentRoute && currentRoute.name in theme.PAGE_BACKGROUND_COLORS) { | ||
currentScreenBackgroundColor = theme.PAGE_BACKGROUND_COLORS[currentRoute.name]; | ||
if (isNested) { | ||
disableRootStatusBar(true); | ||
} | ||
|
||
return () => { | ||
if (!isNested) { | ||
return; | ||
} | ||
StatusBar.setBarStyle('light-content', true); | ||
StatusBar.setBackgroundColor(currentScreenBackgroundColor); | ||
}); | ||
}, [theme.PAGE_BACKGROUND_COLORS, theme.appBG]); | ||
disableRootStatusBar(false); | ||
}; | ||
}, [disableRootStatusBar, isNested]); | ||
|
||
const updateStatusBarStyle = useCallback<EventListenerCallback<NavigationContainerEventMap, 'state'>>(() => { | ||
if (isDisabled) { | ||
return; | ||
} | ||
|
||
// Set the status bar colour depending on the current route. | ||
// If we don't have any colour defined for a route, fall back to | ||
// appBG color. | ||
const currentRoute = navigationRef.getCurrentRoute(); | ||
|
||
let currentScreenBackgroundColor = theme.appBG; | ||
let statusBarStyle = theme.statusBarStyle; | ||
if (currentRoute && 'name' in currentRoute && currentRoute.name in theme.PAGE_THEMES) { | ||
const screenTheme = theme.PAGE_THEMES[currentRoute.name]; | ||
currentScreenBackgroundColor = screenTheme.backgroundColor; | ||
statusBarStyle = screenTheme.statusBarStyle; | ||
} | ||
|
||
StatusBar.setBackgroundColor(currentScreenBackgroundColor, true); | ||
StatusBar.setBarStyle(statusBarStyle, true); | ||
}, [isDisabled, theme.PAGE_THEMES, theme.appBG, theme.statusBarStyle]); | ||
|
||
useEffect(() => { | ||
navigationRef.addListener('state', updateStatusBarStyle); | ||
|
||
return () => navigationRef.removeListener('state', updateStatusBarStyle); | ||
}, [updateStatusBarStyle]); | ||
|
||
useEffect(() => { | ||
if (isDisabled) { | ||
return; | ||
} | ||
|
||
StatusBar.setBarStyle(theme.statusBarStyle, true); | ||
}, [isDisabled, theme.statusBarStyle]); | ||
|
||
if (isDisabled) { | ||
return null; | ||
} | ||
|
||
return <StatusBar />; | ||
}; | ||
|
||
CustomStatusBar.displayName = 'CustomStatusBar'; | ||
CustomStatusBar.propTypes = propTypes; | ||
|
||
export default CustomStatusBar; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import StatusBar from './types'; | ||
|
||
// Only has custom web implementation | ||
StatusBar.getBackgroundColor = () => null; | ||
const setBackgroundColor = StatusBar.setBackgroundColor; | ||
|
||
// We override this because it's not used – on Android our app display edge-to-edge. | ||
// Also because Reanimated's interpolateColor gives Android native colors instead of hex strings, causing this to display a warning. | ||
StatusBar.setBackgroundColor = () => null; | ||
let statusBarColor: string | null = null; | ||
|
||
StatusBar.getBackgroundColor = () => statusBarColor; | ||
|
||
StatusBar.setBackgroundColor = (color, animated = false) => { | ||
statusBarColor = color as string; | ||
setBackgroundColor(color, animated); | ||
}; | ||
|
||
export default StatusBar; |
Oops, something went wrong.