Fix last frame flash

This commit is contained in:
Dan Abramov
2024-11-08 23:51:57 +00:00
parent e7f6bca63d
commit eab9bb82af
4 changed files with 20 additions and 2 deletions
@@ -58,6 +58,7 @@ type Props = {
cropFrameTransform: Transform cropFrameTransform: Transform
cropContentTransform: Transform cropContentTransform: Transform
isResting: boolean isResting: boolean
isHidden: boolean
}> }>
> >
} }
@@ -310,7 +311,7 @@ const ImageItem = ({
) )
const containerStyle = useAnimatedStyle(() => { const containerStyle = useAnimatedStyle(() => {
const {scaleAndMoveTransform} = transforms.value const {scaleAndMoveTransform, isHidden} = transforms.value
// Apply the active adjustments on top of the committed transform before the gestures. // Apply the active adjustments on top of the committed transform before the gestures.
// This is matrix multiplication, so operations are applied in the reverse order. // This is matrix multiplication, so operations are applied in the reverse order.
let t = createTransform() let t = createTransform()
@@ -325,6 +326,7 @@ const ImageItem = ({
] ]
const screenSize = measureSafeArea() const screenSize = measureSafeArea()
return { return {
opacity: isHidden ? 0 : 1,
transform: scaleAndMoveTransform.concat(manipulationTransform), transform: scaleAndMoveTransform.concat(manipulationTransform),
width: screenSize.width, width: screenSize.width,
maxHeight: screenSize.height, maxHeight: screenSize.height,
@@ -55,6 +55,7 @@ type Props = {
cropFrameTransform: Transform cropFrameTransform: Transform
cropContentTransform: Transform cropContentTransform: Transform
isResting: boolean isResting: boolean
isHidden: boolean
}> }>
> >
} }
@@ -145,10 +146,11 @@ const ImageItem = ({
) )
const containerStyle = useAnimatedStyle(() => { const containerStyle = useAnimatedStyle(() => {
const {scaleAndMoveTransform} = transforms.value const {scaleAndMoveTransform, isHidden} = transforms.value
return { return {
flex: 1, flex: 1,
transform: scaleAndMoveTransform, transform: scaleAndMoveTransform,
opacity: isHidden ? 0 : 1,
} }
}) })
@@ -33,6 +33,7 @@ type Props = {
cropFrameTransform: Transform cropFrameTransform: Transform
cropContentTransform: Transform cropContentTransform: Transform
isResting: boolean isResting: boolean
isHidden: boolean
}> }>
> >
} }
@@ -382,6 +382,16 @@ function LightboxImage({
const dismissTranslateY = const dismissTranslateY =
isActive && openProgress.value === 1 ? dismissSwipeTranslateY.value : 0 isActive && openProgress.value === 1 ? dismissSwipeTranslateY.value : 0
if (openProgress.value === 0 && isFlyingAway.value) {
return {
isHidden: true,
isResting: false,
scaleAndMoveTransform: [],
cropFrameTransform: [],
cropContentTransform: [],
}
}
if (isActive && thumbRect && imageAspect && openProgress.value < 1) { if (isActive && thumbRect && imageAspect && openProgress.value < 1) {
return interpolateTransform( return interpolateTransform(
openProgress.value, openProgress.value,
@@ -391,6 +401,7 @@ function LightboxImage({
) )
} }
return { return {
isHidden: false,
isResting: dismissTranslateY === 0, isResting: dismissTranslateY === 0,
scaleAndMoveTransform: [{translateY: dismissTranslateY}], scaleAndMoveTransform: [{translateY: dismissTranslateY}],
cropFrameTransform: [], cropFrameTransform: [],
@@ -628,6 +639,7 @@ function interpolateTransform(
cropFrameTransform: Transform cropFrameTransform: Transform
cropContentTransform: Transform cropContentTransform: Transform
isResting: boolean isResting: boolean
isHidden: boolean
} { } {
'worklet' 'worklet'
const thumbAspect = thumbnailDims.width / thumbnailDims.height const thumbAspect = thumbnailDims.width / thumbnailDims.height
@@ -678,6 +690,7 @@ function interpolateTransform(
[croppedFinalHeight / finalHeight, 1], [croppedFinalHeight / finalHeight, 1],
) )
return { return {
isHidden: false,
isResting: progress === 1, isResting: progress === 1,
scaleAndMoveTransform: [{translateX}, {translateY}, {scale}], scaleAndMoveTransform: [{translateX}, {translateY}, {scale}],
cropFrameTransform: [{scaleX: cropScaleX}, {scaleY: cropScaleY}], cropFrameTransform: [{scaleX: cropScaleX}, {scaleY: cropScaleY}],