about summary refs log tree commit diff
path: root/src/view/com/lightbox/Lightbox.web.tsx
diff options
context:
space:
mode:
authorJaz <ericvolp12@gmail.com>2023-05-30 18:25:29 -0700
committerGitHub <noreply@github.com>2023-05-30 18:25:29 -0700
commit09ade363fdcfadb03433385e0c5510bc58438a65 (patch)
tree710af28d1eb7f70acf81f86acb44759439e164fc /src/view/com/lightbox/Lightbox.web.tsx
parent7f76c2d67e62ba2d10e8b17673a7bbcf7248564f (diff)
parente224569a11b82361d782324a63bdfc19d44a3201 (diff)
downloadvoidsky-09ade363fdcfadb03433385e0c5510bc58438a65.tar.zst
Merge branch 'main' into inherit_system_theme
Diffstat (limited to 'src/view/com/lightbox/Lightbox.web.tsx')
-rw-r--r--src/view/com/lightbox/Lightbox.web.tsx22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/view/com/lightbox/Lightbox.web.tsx b/src/view/com/lightbox/Lightbox.web.tsx
index d389279b1..61446519d 100644
--- a/src/view/com/lightbox/Lightbox.web.tsx
+++ b/src/view/com/lightbox/Lightbox.web.tsx
@@ -65,30 +65,34 @@ function LightboxInner({
 
   const canGoLeft = index >= 1
   const canGoRight = index < imgs.length - 1
-  const onPressLeft = () => {
+  const onPressLeft = useCallback(() => {
     if (canGoLeft) {
       setIndex(index - 1)
     }
-  }
-  const onPressRight = () => {
+  }, [index, canGoLeft])
+  const onPressRight = useCallback(() => {
     if (canGoRight) {
       setIndex(index + 1)
     }
-  }
+  }, [index, canGoRight])
 
-  const onEscape = useCallback(
+  const onKeyDown = useCallback(
     (e: KeyboardEvent) => {
       if (e.key === 'Escape') {
         onClose()
+      } else if (e.key === 'ArrowLeft') {
+        onPressLeft()
+      } else if (e.key === 'ArrowRight') {
+        onPressRight()
       }
     },
-    [onClose],
+    [onClose, onPressLeft, onPressRight],
   )
 
   useEffect(() => {
-    window.addEventListener('keydown', onEscape)
-    return () => window.removeEventListener('keydown', onEscape)
-  }, [onEscape])
+    window.addEventListener('keydown', onKeyDown)
+    return () => window.removeEventListener('keydown', onKeyDown)
+  }, [onKeyDown])
 
   return (
     <View style={styles.mask}>