From 85fb3b8df0ceba6670bc8672463b4d8bfe0001b6 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 26 Jan 2026 14:39:49 +0200 Subject: [PATCH] also defer control rendering --- src/view/com/lightbox/ImageViewing/index.tsx | 58 ++++++++++---------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/view/com/lightbox/ImageViewing/index.tsx b/src/view/com/lightbox/ImageViewing/index.tsx index 946a502d07..25bd88e6d9 100644 --- a/src/view/com/lightbox/ImageViewing/index.tsx +++ b/src/view/com/lightbox/ImageViewing/index.tsx @@ -8,7 +8,7 @@ // Original code copied and simplified from the link below as the codebase is currently not maintained: // https://github.com/jobtoday/react-native-image-viewing -import React, {useCallback, useEffect, useMemo, useState} from 'react' +import {useCallback, useEffect, useMemo, useRef, useState} from 'react' import {LayoutAnimation, PixelRatio, StyleSheet, View} from 'react-native' import {SystemBars} from 'react-native-edge-to-edge' import {Gesture} from 'react-native-gesture-handler' @@ -105,7 +105,7 @@ export default function ImageViewRoot({ setActiveLightbox(nextLightbox) } - React.useEffect(() => { + useEffect(() => { if (!nextLightbox) { return } @@ -140,10 +140,10 @@ export default function ImageViewRoot({ const onOpenProgressChange = useCallback((isOpen: boolean) => { setIsCompletelyOpen(isOpen) if (isOpen) { - ScreenOrientation.unlockAsync() + void ScreenOrientation.unlockAsync() } else { // default is PORTRAIT_UP - set via config plugin in app.config.js -sfn - ScreenOrientation.lockAsync(PORTRAIT_UP) + void ScreenOrientation.lockAsync(PORTRAIT_UP) } }, []) @@ -158,7 +158,7 @@ export default function ImageViewRoot({ }, ) - const onFlyAway = React.useCallback(() => { + const onFlyAway = useCallback(() => { 'worklet' openProgress.set(0) runOnJS(onRequestClose)() @@ -227,7 +227,7 @@ function ImageView({ const [isDragging, setIsDragging] = useState(false) const [imageIndex, setImageIndex] = useState(initialImageIndex) const [showControls, setShowControls] = useState(true) - const [isAltExpanded, setAltExpanded] = React.useState(false) + const [isAltExpanded, setAltExpanded] = useState(false) const dismissSwipeTranslateY = useSharedValue(0) const isFlyingAway = useSharedValue(false) @@ -381,25 +381,27 @@ function ImageView({ ))} - - - - - - setAltExpanded(e => !e)} - onPressSave={onPressSave} - onPressShare={onPressShare} - /> - - + {isCompletelyOpen && ( + + + + + + setAltExpanded(e => !e)} + onPressSave={onPressSave} + onPressShare={onPressShare} + /> + + + )} ) } @@ -431,7 +433,7 @@ function LightboxImage({ openProgress: SharedValue dismissSwipeTranslateY: SharedValue }) { - const [fetchedDims, setFetchedDims] = React.useState(null) + const [fetchedDims, setFetchedDims] = useState(null) const dims = fetchedDims ?? imageSrc.dimensions ?? imageSrc.thumbDimensions let imageAspect: number | undefined if (dims) { @@ -443,7 +445,7 @@ function LightboxImage({ const safeFrameDelayedForJSThreadOnly = useSafeAreaFrame() const safeInsetsDelayedForJSThreadOnly = useSafeAreaInsets() - const measureSafeArea = React.useCallback(() => { + const measureSafeArea = useCallback(() => { 'worklet' let safeArea: Rect | null = measure(safeAreaRef) if (!safeArea) { @@ -580,7 +582,7 @@ function LightboxFooter({ onPressShare: (uri: string) => void }) { const {alt: altText, uri} = images[index] - const isMomentumScrolling = React.useRef(false) + const isMomentumScrolling = useRef(false) return (