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:
dan 2023-11-09 00:25:27 +00:00 committed by GitHub
parent bd531f2344
commit 82059b7ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 55 deletions

View file

@ -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>
)
}