import {createContext, useContext, useEffect, useState} from 'react' import {isWeb} from '#/platform/detection' const LightStatusBarRefCountContext = createContext(false) const SetLightStatusBarRefCountContext = createContext > | 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 (__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 ( 0}> {children} ) }