diff options
-rw-r--r-- | src/view/com/lightbox/Lightbox.web.tsx | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/view/com/lightbox/Lightbox.web.tsx b/src/view/com/lightbox/Lightbox.web.tsx index f10548351..c17356d94 100644 --- a/src/view/com/lightbox/Lightbox.web.tsx +++ b/src/view/com/lightbox/Lightbox.web.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, {useCallback, useEffect} from 'react' import { Image, TouchableOpacity, @@ -73,6 +73,20 @@ function LightboxInner({ } } + const onEscape = useCallback( + (e: KeyboardEvent) => { + if (e.key === 'Escape') { + onClose() + } + }, + [onClose], + ) + + useEffect(() => { + window.addEventListener('keydown', onEscape) + return () => window.removeEventListener('keydown', onEscape) + }, [onEscape]) + return ( <View style={styles.mask}> <TouchableWithoutFeedback onPress={onClose}> |