Fix patch

This commit is contained in:
xmflsct 2024-02-07 00:26:41 +01:00
parent 6f27785a12
commit 7bcef6fe1d
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
2 changed files with 38 additions and 50 deletions

View File

@ -1,50 +0,0 @@
diff --git a/src/android.js b/src/android.js
index fbf09855771f985c5edfc53c22cf6cfe828f45f9..7751d456e08e2dc4c78601fc9430fdbf1373e0d4 100644
--- a/src/android.js
+++ b/src/android.js
@@ -16,7 +16,7 @@ import TextAncestor from 'react-native/Libraries/Text/TextAncestor';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
import invariant from 'invariant';
import nullthrows from 'nullthrows';
-import setAndForwardRef from 'react-native/Libraries/Utilities/setAndForwardRef';
+import setAndForwardRef from './setAndForwardRef';
import usePressability from 'react-native/Libraries/Pressability/usePressability';
diff --git a/src/ios.tsx b/src/ios.tsx
index b9ed28bbf9fca6fb44c27096e771d8d2b65b858f..588a75c82b2ee1123d3e48acb984bcbc8b293cc8 100644
--- a/src/ios.tsx
+++ b/src/ios.tsx
@@ -11,7 +11,7 @@ import {
} from 'react-native';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
import TextAncestor from 'react-native/Libraries/Text/TextAncestor';
-import setAndForwardRef from 'react-native/Libraries/Utilities/setAndForwardRef';
+import setAndForwardRef from './setAndForwardRef';
import { getTextInputExtraProps } from './extra_props';
import type {
diff --git a/src/setAndForwardRef.js b/src/setAndForwardRef.js
new file mode 100644
index 0000000000000000000000000000000000000000..ad7777e271b945c7123953f7578a8d1208ca9e48
--- /dev/null
+++ b/src/setAndForwardRef.js
@@ -0,0 +1,17 @@
+function setAndForwardRef({ getForwardedRef, setLocalRef }) {
+ return function forwardRef(ref) {
+ const forwardedRef = getForwardedRef();
+
+ setLocalRef(ref);
+
+ // Forward to user ref prop (if one has been specified)
+ if (typeof forwardedRef === 'function') {
+ // Handle function-based refs. String-based refs are handled as functions.
+ forwardedRef(ref);
+ } else if (typeof forwardedRef === 'object' && forwardedRef != null) {
+ // Handle createRef-based refs
+ forwardedRef.current = ref;
+ }
+ };
+}
+export default setAndForwardRef;
\ No newline at end of file

View File

@ -0,0 +1,38 @@
diff --git a/src/zoom.tsx b/src/zoom.tsx
index 70ce1c8d6a43e711f06b93d1eda3b44a3ad9a659..cdc2713470f2d332b8bf3e9c97e38fd9b78281df 100644
--- a/src/zoom.tsx
+++ b/src/zoom.tsx
@@ -4,6 +4,7 @@ import Animated, {
useSharedValue,
useAnimatedStyle,
useDerivedValue,
+ withDecay,
withTiming,
cancelAnimation,
runOnJS,
@@ -120,11 +121,22 @@ export function Zoom(props: Props) {
}
}
})
- .onEnd(() => {
+ .onEnd((event) => {
if (isPinching.value || !isZoomed.value) return;
- panTranslateX.value = 0;
- panTranslateY.value = 0;
+ const maxTranslateX = (viewWidth.value / 2) * scale.value - viewWidth.value / 2;
+ const minTranslateX = -maxTranslateX;
+ translationX.value = withDecay({
+ velocity: event.velocityX,
+ clamp: [minTranslateX, maxTranslateX]
+ });
+
+ const maxTranslateY = (viewHeight.value / 2) * scale.value - viewHeight.value / 2;
+ const minTranslateY = -maxTranslateY;
+ translationY.value = withDecay({
+ velocity: event.velocityY,
+ clamp: [minTranslateY, maxTranslateY]
+ });
});
const pinch = Gesture.Pinch()