about summary refs log tree commit diff
path: root/src/state/dialogs/index.tsx
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2025-08-14 01:11:44 +0300
committerGitHub <noreply@github.com>2025-08-14 01:11:44 +0300
commit275fece3e3de0bd09377a33813bcfe35e352874b (patch)
tree60f1376c319cf0b5a12f6a065d33de21b8917b27 /src/state/dialogs/index.tsx
parenteef639ea54f2309e6da18a293e07d54b7953f626 (diff)
downloadvoidsky-275fece3e3de0bd09377a33813bcfe35e352874b.tar.zst
[Perf - part 3] Stop every dialog control in the entire app rerendering when opening a dialog (#8815)
Diffstat (limited to 'src/state/dialogs/index.tsx')
-rw-r--r--src/state/dialogs/index.tsx31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/state/dialogs/index.tsx b/src/state/dialogs/index.tsx
index f770e9c16..520fb2c84 100644
--- a/src/state/dialogs/index.tsx
+++ b/src/state/dialogs/index.tsx
@@ -1,7 +1,7 @@
 import React from 'react'
 
 import {isWeb} from '#/platform/detection'
-import {DialogControlRefProps} from '#/components/Dialog'
+import {type DialogControlRefProps} from '#/components/Dialog'
 import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
 import {BottomSheetNativeComponent} from '../../../modules/bottom-sheet'
 
@@ -22,11 +22,6 @@ interface IDialogContext {
 interface IDialogControlContext {
   closeAllDialogs(): boolean
   setDialogIsOpen(id: string, isOpen: boolean): void
-  /**
-   * The number of dialogs that are fully expanded. This is used to determine the backgground color of the status bar
-   * on iOS.
-   */
-  fullyExpandedCount: number
   setFullyExpandedCount: React.Dispatch<React.SetStateAction<number>>
 }
 
@@ -36,6 +31,13 @@ const DialogControlContext = React.createContext<IDialogControlContext>(
   {} as IDialogControlContext,
 )
 
+/**
+ * The number of dialogs that are fully expanded. This is used to determine the background color of the status bar
+ * on iOS.
+ */
+const DialogFullyExpandedCountContext = React.createContext<number>(0)
+DialogFullyExpandedCountContext.displayName = 'DialogFullyExpandedCountContext'
+
 export function useDialogStateContext() {
   return React.useContext(DialogContext)
 }
@@ -44,6 +46,11 @@ export function useDialogStateControlContext() {
   return React.useContext(DialogControlContext)
 }
 
+/** The number of dialogs that are fully expanded */
+export function useDialogFullyExpandedCountContext() {
+  return React.useContext(DialogFullyExpandedCountContext)
+}
+
 export function Provider({children}: React.PropsWithChildren<{}>) {
   const [fullyExpandedCount, setFullyExpandedCount] = React.useState(0)
 
@@ -85,21 +92,17 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
     () => ({
       closeAllDialogs,
       setDialogIsOpen,
-      fullyExpandedCount,
       setFullyExpandedCount,
     }),
-    [
-      closeAllDialogs,
-      setDialogIsOpen,
-      fullyExpandedCount,
-      setFullyExpandedCount,
-    ],
+    [closeAllDialogs, setDialogIsOpen, setFullyExpandedCount],
   )
 
   return (
     <DialogContext.Provider value={context}>
       <DialogControlContext.Provider value={controls}>
-        <GlobalDialogsProvider>{children}</GlobalDialogsProvider>
+        <DialogFullyExpandedCountContext.Provider value={fullyExpandedCount}>
+          <GlobalDialogsProvider>{children}</GlobalDialogsProvider>
+        </DialogFullyExpandedCountContext.Provider>
       </DialogControlContext.Provider>
     </DialogContext.Provider>
   )