mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at thread-bug 50 lines 1.0 kB view raw
1import React from 'react' 2import {type SharedValue, useSharedValue} from 'react-native-reanimated' 3 4type StateContext = { 5 headerHeight: SharedValue<number> 6 footerHeight: SharedValue<number> 7} 8 9const stateContext = React.createContext<StateContext>({ 10 headerHeight: { 11 value: 0, 12 addListener() {}, 13 removeListener() {}, 14 modify() {}, 15 get() { 16 return 0 17 }, 18 set() {}, 19 }, 20 footerHeight: { 21 value: 0, 22 addListener() {}, 23 removeListener() {}, 24 modify() {}, 25 get() { 26 return 0 27 }, 28 set() {}, 29 }, 30}) 31stateContext.displayName = 'ShellLayoutContext' 32 33export function Provider({children}: React.PropsWithChildren<{}>) { 34 const headerHeight = useSharedValue(0) 35 const footerHeight = useSharedValue(0) 36 37 const value = React.useMemo( 38 () => ({ 39 headerHeight, 40 footerHeight, 41 }), 42 [headerHeight, footerHeight], 43 ) 44 45 return <stateContext.Provider value={value}>{children}</stateContext.Provider> 46} 47 48export function useShellLayout() { 49 return React.useContext(stateContext) 50}