diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-12-12 17:46:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-12 17:46:19 +0000 |
commit | ffc63dc85fc191a51c3dc12c1afcd250f95036d5 (patch) | |
tree | d48124c74c24662abf9ee28ff6fbbdd4b1d8ee99 /src/state/shell/light-status-bar.tsx | |
parent | 4b32b0a71be4669fa0741efc46d646093c3114f5 (diff) | |
download | voidsky-ffc63dc85fc191a51c3dc12c1afcd250f95036d5.tar.zst |
[Layout] Bleed profile banner into safe area (#6967)
* bleed profile banner into safe area (cherry picked from commit 50b3a4d0c6fd94b583ffe4efa65de35c81ae7f4e) * pointer events none when hidden (cherry picked from commit bae2c7b2dd6d7f858a98812196628308c0877755) * fix web (cherry picked from commit e3f9597170375f2903b6e567b963f008ec95aed1) * add status bar shadow * rm log * rm mini header * speed up animation * pass bool rather than int in light status bar
Diffstat (limited to 'src/state/shell/light-status-bar.tsx')
-rw-r--r-- | src/state/shell/light-status-bar.tsx | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/state/shell/light-status-bar.tsx b/src/state/shell/light-status-bar.tsx new file mode 100644 index 000000000..eb213adb9 --- /dev/null +++ b/src/state/shell/light-status-bar.tsx @@ -0,0 +1,45 @@ +import {createContext, useContext, useEffect, useState} from 'react' + +import {isWeb} from '#/platform/detection' +import {IS_DEV} from '#/env' + +const LightStatusBarRefCountContext = createContext<boolean>(false) +const SetLightStatusBarRefCountContext = createContext<React.Dispatch< + React.SetStateAction<number> +> | null>(null) + +export function useLightStatusBar() { + return useContext(LightStatusBarRefCountContext) +} + +export function useSetLightStatusBar(enabled: boolean) { + const setRefCount = useContext(SetLightStatusBarRefCountContext) + useEffect(() => { + // noop on web -sfn + if (isWeb) return + + if (!setRefCount) { + if (IS_DEV) + console.error( + 'useLightStatusBar was used without a SetLightStatusBarRefCountContext provider', + ) + return + } + if (enabled) { + setRefCount(prev => prev + 1) + return () => setRefCount(prev => prev - 1) + } + }, [enabled, setRefCount]) +} + +export function Provider({children}: React.PropsWithChildren<{}>) { + const [refCount, setRefCount] = useState(0) + + return ( + <SetLightStatusBarRefCountContext.Provider value={setRefCount}> + <LightStatusBarRefCountContext.Provider value={refCount > 0}> + {children} + </LightStatusBarRefCountContext.Provider> + </SetLightStatusBarRefCountContext.Provider> + ) +} |