An ATproto social media client -- with an independent Appview.

Fix stuck lightbox (#6166)

* Add early exit guards once the gesture is over

* Work around the Reanimated bug

* Move derived reaction upwards to avoid duplicating it

authored by danabra.mov and committed by

GitHub ce8d62f8 7c45f7dc

+28 -16
+28 -16
src/view/com/lightbox/ImageViewing/index.tsx
··· 160 160 } 161 161 }, []) 162 162 163 + useAnimatedReaction( 164 + () => { 165 + const screenSize = measure(safeAreaRef) 166 + return ( 167 + !screenSize || 168 + Math.abs(dismissSwipeTranslateY.value) > screenSize.height 169 + ) 170 + }, 171 + (isOut, wasOut) => { 172 + if (isOut && !wasOut) { 173 + // Stop the animation from blocking the screen forever. 174 + cancelAnimation(dismissSwipeTranslateY) 175 + runOnJS(onRequestClose)() 176 + } 177 + }, 178 + ) 179 + 163 180 return ( 164 181 <Animated.View style={[styles.container, containerStyle]}> 165 182 <Animated.View ··· 256 273 .maxPointers(1) 257 274 .onUpdate(e => { 258 275 'worklet' 276 + if (isFlyingAway.value) { 277 + return 278 + } 259 279 dismissSwipeTranslateY.value = e.translationY 260 280 }) 261 281 .onEnd(e => { 262 282 'worklet' 283 + if (isFlyingAway.value) { 284 + return 285 + } 263 286 if (Math.abs(e.velocityY) > 1000) { 264 287 isFlyingAway.value = true 288 + if (dismissSwipeTranslateY.value === 0) { 289 + // HACK: If the initial value is 0, withDecay() animation doesn't start. 290 + // This is a bug in Reanimated, but for now we'll work around it like this. 291 + dismissSwipeTranslateY.value = 1 292 + } 265 293 dismissSwipeTranslateY.value = withDecay({ 266 294 velocity: e.velocityY, 267 295 velocityFactor: Math.max(3000 / Math.abs(e.velocityY), 1), // Speed up if it's too slow. ··· 274 302 }) 275 303 } 276 304 }) 277 - useAnimatedReaction( 278 - () => { 279 - const screenSize = measure(safeAreaRef) 280 - return ( 281 - !screenSize || 282 - Math.abs(dismissSwipeTranslateY.value) > screenSize.height 283 - ) 284 - }, 285 - (isOut, wasOut) => { 286 - if (isOut && !wasOut) { 287 - // Stop the animation from blocking the screen forever. 288 - cancelAnimation(dismissSwipeTranslateY) 289 - runOnJS(onRequestClose)() 290 - } 291 - }, 292 - ) 293 305 294 306 const imageStyle = useAnimatedStyle(() => { 295 307 return {