diff --git a/src/view/com/lightbox/ImageViewing/index.tsx b/src/view/com/lightbox/ImageViewing/index.tsx index ebc18c69ce..946a502d07 100644 --- a/src/view/com/lightbox/ImageViewing/index.tsx +++ b/src/view/com/lightbox/ImageViewing/index.tsx @@ -98,6 +98,8 @@ export default function ImageViewRoot({ 'portrait', ) const openProgress = useSharedValue(0) + // mirrors `openProgress`, but just a bool, used for deferring rendering other images + const [isCompletelyOpen, setIsCompletelyOpen] = useState(false) if (!activeLightbox && nextLightbox) { setActiveLightbox(nextLightbox) @@ -135,16 +137,23 @@ export default function ImageViewRoot({ }, ) + const onOpenProgressChange = useCallback((isOpen: boolean) => { + setIsCompletelyOpen(isOpen) + if (isOpen) { + ScreenOrientation.unlockAsync() + } else { + // default is PORTRAIT_UP - set via config plugin in app.config.js -sfn + ScreenOrientation.lockAsync(PORTRAIT_UP) + } + }, []) + // Delay the unlock until after we've finished the scale up animation. // It's complicated to do the same for locking it back so we don't attempt that. useAnimatedReaction( () => openProgress.get() === 1, (isOpen, wasOpen) => { - if (isOpen && !wasOpen) { - runOnJS(ScreenOrientation.unlockAsync)() - } else if (!isOpen && wasOpen) { - // default is PORTRAIT_UP - set via config plugin in app.config.js -sfn - runOnJS(ScreenOrientation.lockAsync)(PORTRAIT_UP) + if (isOpen !== wasOpen) { + runOnJS(onOpenProgressChange)(isOpen) } }, ) @@ -183,6 +192,7 @@ export default function ImageViewRoot({ onFlyAway={onFlyAway} safeAreaRef={ref} openProgress={openProgress} + isCompletelyOpen={isCompletelyOpen} /> )} @@ -199,6 +209,7 @@ function ImageView({ onFlyAway, safeAreaRef, openProgress, + isCompletelyOpen, }: { lightbox: Lightbox orientation: 'portrait' | 'landscape' @@ -208,6 +219,7 @@ function ImageView({ onFlyAway: () => void safeAreaRef: AnimatedRef openProgress: SharedValue + isCompletelyOpen: boolean }) { const {images, index: initialImageIndex} = lightbox const isAnimated = useMemo(() => canAnimate(lightbox), [lightbox]) @@ -350,20 +362,22 @@ function ImageView({ style={styles.pager}> {images.map((imageSrc, i) => ( - + {(isCompletelyOpen || i === imageIndex) && ( + + )} ))}