diff options
author | Mathieu Acthernoene <zoontek@gmail.com> | 2025-04-22 18:16:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-22 19:16:50 +0300 |
commit | a770f5635b549f2a87ffeaedd031dfe8e37b58c8 (patch) | |
tree | 2e935d294227e57b2e81ba79ba96a6a85f268971 /src/state/shell/light-status-bar.tsx | |
parent | 6e80b340c825900524bfe981ba29cfd0c6cf5934 (diff) | |
download | voidsky-a770f5635b549f2a87ffeaedd031dfe8e37b58c8.tar.zst |
Edge to edge support (#7497)
Diffstat (limited to 'src/state/shell/light-status-bar.tsx')
-rw-r--r-- | src/state/shell/light-status-bar.tsx | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/src/state/shell/light-status-bar.tsx b/src/state/shell/light-status-bar.tsx index 6f47689d1..80df9ad90 100644 --- a/src/state/shell/light-status-bar.tsx +++ b/src/state/shell/light-status-bar.tsx @@ -1,44 +1,17 @@ -import {createContext, useContext, useEffect, useState} from 'react' - -import {isWeb} from '#/platform/detection' - -const LightStatusBarRefCountContext = createContext<boolean>(false) -const SetLightStatusBarRefCountContext = createContext<React.Dispatch< - React.SetStateAction<number> -> | null>(null) - -export function useLightStatusBar() { - return useContext(LightStatusBarRefCountContext) -} +import {useEffect} from 'react' +import {SystemBars} from 'react-native-edge-to-edge' export function useSetLightStatusBar(enabled: boolean) { - const setRefCount = useContext(SetLightStatusBarRefCountContext) useEffect(() => { - // noop on web -sfn - if (isWeb) return - - if (!setRefCount) { - if (__DEV__) - console.error( - 'useLightStatusBar was used without a SetLightStatusBarRefCountContext provider', - ) - return - } if (enabled) { - setRefCount(prev => prev + 1) - return () => setRefCount(prev => prev - 1) + const entry = SystemBars.pushStackEntry({ + style: { + statusBar: 'light', + }, + }) + return () => { + SystemBars.popStackEntry(entry) + } } - }, [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> - ) + }, [enabled]) } |