Create global keyboard shortcut handler (#10145)

This commit is contained in:
DS Boyce
2026-04-03 10:06:51 -07:00
committed by GitHub
parent e0ea778e58
commit cca3326b21
16 changed files with 257 additions and 182 deletions
+18 -8
View File
@@ -7,6 +7,7 @@ import {
useState,
} from 'react'
import {useHotkeysContext} from '#/lib/hotkeys'
import {type DialogControlRefProps} from '#/components/Dialog'
import {Provider as GlobalDialogsProvider} from '#/components/dialogs/Context'
import {IS_WEB} from '#/env'
@@ -62,6 +63,7 @@ export function useDialogFullyExpandedCountContext() {
export function Provider({children}: React.PropsWithChildren<{}>) {
const [fullyExpandedCount, setFullyExpandedCount] = useState(0)
const {disableScope, enableScope} = useHotkeysContext()
const activeDialogs = useRef<
Map<string, React.MutableRefObject<DialogControlRefProps>>
@@ -77,18 +79,26 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
return openDialogs.current.size > 0
} else {
BottomSheetNativeComponent.dismissAll()
void BottomSheetNativeComponent.dismissAll()
return false
}
}, [])
const setDialogIsOpen = useCallback((id: string, isOpen: boolean) => {
if (isOpen) {
openDialogs.current.add(id)
} else {
openDialogs.current.delete(id)
}
}, [])
const setDialogIsOpen = useCallback(
(id: string, isOpen: boolean) => {
if (isOpen) {
openDialogs.current.add(id)
} else {
openDialogs.current.delete(id)
}
if (openDialogs.current.size > 0) {
disableScope('global')
} else {
enableScope('global')
}
},
[disableScope, enableScope],
)
const context = useMemo<IDialogContext>(
() => ({