about summary refs log tree commit diff
path: root/src/state/shell/minimal-mode.tsx
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-11-09 00:25:27 +0000
committerGitHub <noreply@github.com>2023-11-09 00:25:27 +0000
commit82059b7ee138d24ff50b0f4fad0eaeac860bb78c (patch)
tree05db1953b6405d218d3a23d3030dab47a10e05ec /src/state/shell/minimal-mode.tsx
parentbd531f2344c181261afaf8c43c96daf569b58f09 (diff)
downloadvoidsky-82059b7ee138d24ff50b0f4fad0eaeac860bb78c.tar.zst
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
Diffstat (limited to 'src/state/shell/minimal-mode.tsx')
-rw-r--r--src/state/shell/minimal-mode.tsx22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/state/shell/minimal-mode.tsx b/src/state/shell/minimal-mode.tsx
index 4909a9a65..b506c21db 100644
--- a/src/state/shell/minimal-mode.tsx
+++ b/src/state/shell/minimal-mode.tsx
@@ -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>
   )
 }