Skip to content

Commit

Permalink
Fix multiple double taps, reduce velocity on edges
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbabenko committed Nov 23, 2023
1 parent 122c0e4 commit 8939bd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ const ResizableImage = React.memo(
focalY,
}: Record<'focalX' | 'focalY', number>) => {
'worklet';

adjustedFocal.x.value = focalX - (CENTER.x + offset.x.value);
adjustedFocal.y.value = focalY - (CENTER.y + offset.y.value);
};
Expand Down Expand Up @@ -536,13 +535,15 @@ const ResizableImage = React.memo(
const newWidth = scale.value * layout.x.value;
const newHeight = scale.value * layout.y.value;
if (
isMoving.x.value &&
offset.x.value < (newWidth - width) / 2 - translation.x.value &&
offset.x.value > -(newWidth - width) / 2 - translation.x.value
) {
cancelAnimation(offset.x);
}

if (
isMoving.y.value &&
offset.y.value < (newHeight - height) / 2 - translation.y.value &&
offset.y.value > -(newHeight - height) / 2 - translation.y.value
) {
Expand Down Expand Up @@ -717,12 +718,9 @@ const ResizableImage = React.memo(
(newWidth - width) / 2 - translation.x.value,
],
},
(edge) => {
() => {
'worklet';
isMoving.x.value = 0;
if (edge.isEdge) {
isMoving.y.value = 0;
}
}
);
}
Expand All @@ -745,12 +743,9 @@ const ResizableImage = React.memo(
(newHeight - height) / 2 - translation.y.value,
],
},
(edge) => {
() => {
'worklet';
isMoving.y.value = 0;
if (edge.isEdge) {
isMoving.x.value = 0;
}
}
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/withDecaySpring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function withDecaySpring(
animation.toValue =
nextX <= config.clamp[0] ? config.clamp[0] : config.clamp[1];

callback?.({ isEdge: true });
v = v / 3;
}
}
}
Expand Down

0 comments on commit 8939bd0

Please sign in to comment.