fix: Fixes issue where preferences view would not close after pressing Escape

This commit is contained in:
Aman Harwara
2023-02-27 14:13:39 +05:30
parent 3c1dc10504
commit 6c120ffde2
3 changed files with 7 additions and 13 deletions

View File

@@ -189,6 +189,7 @@ export class KeyboardService {
this.commandHandlers.push(observer) this.commandHandlers.push(observer)
const thislessObservers = this.commandHandlers const thislessObservers = this.commandHandlers
console.log(thislessObservers)
return () => { return () => {
observer.onKeyDown = undefined observer.onKeyDown = undefined
observer.onKeyDown = undefined observer.onKeyDown = undefined

View File

@@ -6,7 +6,6 @@ import PreferencesCanvas from './PreferencesCanvas'
import { PreferencesProps } from './PreferencesProps' import { PreferencesProps } from './PreferencesProps'
import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile' import { useDisableBodyScrollOnMobile } from '@/Hooks/useDisableBodyScrollOnMobile'
import { useAndroidBackHandler } from '@/NativeMobileWeb/useAndroidBackHandler' import { useAndroidBackHandler } from '@/NativeMobileWeb/useAndroidBackHandler'
import { ESCAPE_COMMAND } from '@standardnotes/ui-services'
import Modal from '../Modal/Modal' import Modal from '../Modal/Modal'
import { classNames } from '@standardnotes/snjs' import { classNames } from '@standardnotes/snjs'
import { isIOS } from '@/Utils' import { isIOS } from '@/Utils'
@@ -25,17 +24,7 @@ const PreferencesView: FunctionComponent<PreferencesProps> = ({
useEffect(() => { useEffect(() => {
menu.selectPane(viewControllerManager.preferencesController.currentPane) menu.selectPane(viewControllerManager.preferencesController.currentPane)
const removeEscKeyObserver = application.keyboardService.addCommandHandler({ }, [menu, viewControllerManager.preferencesController.currentPane])
command: ESCAPE_COMMAND,
onKeyDown: (event) => {
event.preventDefault()
closePreferences()
},
})
return () => {
removeEscKeyObserver()
}
}, [menu, viewControllerManager.preferencesController.currentPane, application.keyboardService, closePreferences])
useDisableBodyScrollOnMobile() useDisableBodyScrollOnMobile()

View File

@@ -20,7 +20,11 @@ const PreferencesViewWrapper: FunctionComponent<PreferencesViewWrapperProps> = (
}, [commandService, viewControllerManager]) }, [commandService, viewControllerManager])
return ( return (
<ModalOverlay isOpen={viewControllerManager.preferencesController?.isOpen} className="p-0"> <ModalOverlay
isOpen={viewControllerManager.preferencesController.isOpen}
onDismiss={viewControllerManager.preferencesController.closePreferences}
className="p-0"
>
<PreferencesView <PreferencesView
closePreferences={() => viewControllerManager.preferencesController.closePreferences()} closePreferences={() => viewControllerManager.preferencesController.closePreferences()}
application={application} application={application}