about summary refs log tree commit diff
path: root/src/view/com/lightbox/ImageViewing/index.tsx
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-10-13 20:10:27 +0100
committerGitHub <noreply@github.com>2023-10-13 20:10:27 +0100
commitabfd9a8c0b850424ebf26da0841f25ecacfd8407 (patch)
tree02ef37f30e7b7f5eb4972de3a06fa4d9b6af6585 /src/view/com/lightbox/ImageViewing/index.tsx
parentf447eaa6692c46921bf1124e2cfe2f030f0cc08d (diff)
downloadvoidsky-abfd9a8c0b850424ebf26da0841f25ecacfd8407.tar.zst
Toggle lightbox controls on tap (#1687)
* Make the lightbox controls animation smoother

* Toggle controls on tap

* Disable pointer events when hidden
Diffstat (limited to 'src/view/com/lightbox/ImageViewing/index.tsx')
-rw-r--r--src/view/com/lightbox/ImageViewing/index.tsx19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/view/com/lightbox/ImageViewing/index.tsx b/src/view/com/lightbox/ImageViewing/index.tsx
index 78d16f8a6..b6835793d 100644
--- a/src/view/com/lightbox/ImageViewing/index.tsx
+++ b/src/view/com/lightbox/ImageViewing/index.tsx
@@ -43,24 +43,36 @@ function ImageViewing({
   const [isScaled, setIsScaled] = useState(false)
   const [isDragging, setIsDragging] = useState(false)
   const [imageIndex, setImageIndex] = useState(initialImageIndex)
+  const [showControls, setShowControls] = useState(true)
 
   const animatedHeaderStyle = useAnimatedStyle(() => ({
+    pointerEvents: showControls ? 'auto' : 'none',
+    opacity: withClampedSpring(showControls ? 1 : 0),
     transform: [
       {
-        translateY: withClampedSpring(isScaled ? -300 : 0),
+        translateY: withClampedSpring(showControls ? 0 : -30),
       },
     ],
   }))
   const animatedFooterStyle = useAnimatedStyle(() => ({
+    pointerEvents: showControls ? 'auto' : 'none',
+    opacity: withClampedSpring(showControls ? 1 : 0),
     transform: [
       {
-        translateY: withClampedSpring(isScaled ? 300 : 0),
+        translateY: withClampedSpring(showControls ? 0 : 30),
       },
     ],
   }))
 
+  const onTap = useCallback(() => {
+    setShowControls(show => !show)
+  }, [])
+
   const onZoom = useCallback((nextIsScaled: boolean) => {
     setIsScaled(nextIsScaled)
+    if (nextIsScaled) {
+      setShowControls(false)
+    }
   }, [])
 
   const edges = useMemo(() => {
@@ -105,6 +117,7 @@ function ImageViewing({
           {images.map(imageSrc => (
             <View key={imageSrc.uri}>
               <ImageItem
+                onTap={onTap}
                 onZoom={onZoom}
                 imageSrc={imageSrc}
                 onRequestClose={onRequestClose}
@@ -161,7 +174,7 @@ const EnhancedImageViewing = (props: Props) => (
 
 function withClampedSpring(value: any) {
   'worklet'
-  return withSpring(value, {overshootClamping: true})
+  return withSpring(value, {overshootClamping: true, stiffness: 300})
 }
 
 export default EnhancedImageViewing