import React from 'react' import { cancelAnimation, SharedValue, useSharedValue, withSpring, } from 'react-native-reanimated' type StateContext = { headerMode: SharedValue footerMode: SharedValue } type SetContext = (v: boolean) => void const stateContext = React.createContext({ headerMode: { value: 0, addListener() {}, removeListener() {}, modify() {}, }, footerMode: { value: 0, addListener() {}, removeListener() {}, modify() {}, }, }) const setContext = React.createContext((_: boolean) => {}) export function Provider({children}: React.PropsWithChildren<{}>) { const headerMode = useSharedValue(0) const footerMode = useSharedValue(0) const setMode = React.useCallback( (v: boolean) => { 'worklet' // Cancel any existing animation cancelAnimation(headerMode) headerMode.value = withSpring(v ? 1 : 0, { overshootClamping: true, }) cancelAnimation(footerMode) footerMode.value = withSpring(v ? 1 : 0, { overshootClamping: true, }) }, [headerMode, footerMode], ) const value = React.useMemo( () => ({ headerMode, footerMode, }), [headerMode, footerMode], ) return ( {children} ) } export function useMinimalShellMode() { return React.useContext(stateContext) } export function useSetMinimalShellMode() { return React.useContext(setContext) }