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)
const thislessObservers = this.commandHandlers
console.log(thislessObservers)
return () => {
observer.onKeyDown = undefined
observer.onKeyDown = undefined

View File

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

View File

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