Skip to content

Commit

Permalink
update status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
SorinC6 committed Apr 30, 2024
1 parent 74cc966 commit 997d992
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions apps/wallet-mobile/src/components/hooks/useStatusBar.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,50 @@
import {Palette, useTheme} from '@yoroi/theme'
import {ThemedPalette, useTheme} from '@yoroi/theme'
import * as React from 'react'
import {Platform, StatusBar, StatusBarStyle} from 'react-native'

import {COLORS} from '../../theme/config'
import {HexColor} from '../../theme/types'

type StatusBarColor = {
bgColorAndroid: HexColor
statusBarStyle: StatusBarStyle
}
export const useStatusBar = (currentRouteName: string | undefined) => {
const {
theme: {color: palette},
isDark,
} = useTheme()
const {color, isDark} = useTheme()
const statusBarStyleByRoute = React.useRef<StatusBarColor>(
getStatusBarStyleByRoute({currentRouteName, isDark, palette}),
getStatusBarStyleByRoute({currentRouteName, isDark, color}),
)

React.useEffect(() => {
if (currentRouteName === 'modal') {
if (Platform.OS === 'android')
StatusBar.setBackgroundColor(simulateOpacity(statusBarStyleByRoute.current.bgColorAndroid), true)
} else {
const style = getStatusBarStyleByRoute({currentRouteName, isDark, palette})
const style = getStatusBarStyleByRoute({currentRouteName, isDark, color})
statusBarStyleByRoute.current = style
if (Platform.OS === 'android') StatusBar.setBackgroundColor(style.bgColorAndroid, true)
StatusBar.setBarStyle(style.statusBarStyle, true)
}
}, [currentRouteName, isDark, palette])
}, [currentRouteName, isDark, color])
}

const getStatusBarStyleByRoute = ({
currentRouteName,
isDark,
palette,
color,
}: {
currentRouteName: string | undefined
isDark?: boolean
palette: Palette
color: ThemedPalette
}): StatusBarColor => {
if (currentRouteName) {
if (currentRouteName === 'history-list') {
return {
bgColorAndroid: palette.primary[100],
bgColorAndroid: color.primary_c100,
statusBarStyle: 'dark-content',
}
} else if (oldBlueRoutes.includes(currentRouteName)) {
return {
bgColorAndroid: COLORS.BACKGROUND_BLUE as HexColor,
bgColorAndroid: '#254BC9',
statusBarStyle: 'light-content',
}
} else if (currentRouteName === 'scan-start') {
Expand Down

0 comments on commit 997d992

Please sign in to comment.