Hide/show header and footer without re-renders, take two (#1849)
* Remove callsites using the state value * Remove unused code * Change shell mode without re-renders * Adjust "write your reply" for mode
This commit is contained in:
parent
bd531f2344
commit
82059b7ee1
7 changed files with 63 additions and 55 deletions
|
@ -1,16 +1,28 @@
|
|||
import React from 'react'
|
||||
import {useSharedValue, SharedValue} from 'react-native-reanimated'
|
||||
|
||||
type StateContext = boolean
|
||||
type StateContext = SharedValue<boolean>
|
||||
type SetContext = (v: boolean) => void
|
||||
|
||||
const stateContext = React.createContext<StateContext>(false)
|
||||
const stateContext = React.createContext<StateContext>({
|
||||
value: false,
|
||||
addListener() {},
|
||||
removeListener() {},
|
||||
modify() {},
|
||||
})
|
||||
const setContext = React.createContext<SetContext>((_: boolean) => {})
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [state, setState] = React.useState(false)
|
||||
const mode = useSharedValue(false)
|
||||
const setMode = React.useCallback(
|
||||
(v: boolean) => {
|
||||
mode.value = v
|
||||
},
|
||||
[mode],
|
||||
)
|
||||
return (
|
||||
<stateContext.Provider value={state}>
|
||||
<setContext.Provider value={setState}>{children}</setContext.Provider>
|
||||
<stateContext.Provider value={mode}>
|
||||
<setContext.Provider value={setMode}>{children}</setContext.Provider>
|
||||
</stateContext.Provider>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue