oblador / react-native-pinchable

Instagram like pinch to zoom for React Native
MIT License
229 stars 26 forks source link

onActive event needed to disable other gestures #24

Open felix-phil opened 2 months ago

felix-phil commented 2 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-pinchable@0.2.1 for the project I'm working on.

I needed to know when pinching is active or not in order to disable all other gestures as the library is crashing iOS devices while pinching is active and other gestures are also active

Here is the diff that solved my problem:


diff --git a/node_modules/react-native-pinchable/android/src/main/java/com/oblador/pinchable/PinchableView.java b/node_modules/react-native-pinchable/android/src/main/java/com/oblador/pinchable/PinchableView.java
index 9f22074..1419b50 100644
--- a/node_modules/react-native-pinchable/android/src/main/java/com/oblador/pinchable/PinchableView.java
+++ b/node_modules/react-native-pinchable/android/src/main/java/com/oblador/pinchable/PinchableView.java
@@ -18,6 +18,11 @@ import android.animation.ValueAnimator;
 import android.view.animation.DecelerateInterpolator;

 import com.facebook.react.views.view.ReactViewGroup;
+import com.facebook.react.uimanager.events.RCTEventEmitter;
+import com.facebook.react.bridge.WritableMap;
+import com.facebook.react.bridge.Arguments;
+
+import javax.annotation.Nullable;

 public class PinchableView extends ReactViewGroup implements OnTouchListener {
     private final int animationDuration = 400;
@@ -34,6 +39,8 @@ public class PinchableView extends ReactViewGroup implements OnTouchListener {
     private ColorDrawable backdrop = null;
     private BitmapDrawable clone = null;

+    private @Nullable RCTEventEmitter mEventEmitter;
+
     public PinchableView(Context context) {
         super(context);
         this.setOnTouchListener(this);
@@ -122,6 +129,7 @@ public class PinchableView extends ReactViewGroup implements OnTouchListener {
         }

         active = true;
+        setOnActive(true);

         if (backdrop == null) {
             backdrop = new ColorDrawable(Color.BLACK);
@@ -195,6 +203,7 @@ public class PinchableView extends ReactViewGroup implements OnTouchListener {
             clone = null;
         }
         setVisibility(View.VISIBLE);
+        setOnActive(false);
     }

     public void setMinimumZoomScale(float minimumZoomScale) {
@@ -204,4 +213,16 @@ public class PinchableView extends ReactViewGroup implements OnTouchListener {
     public void setMaximumZoomScale(float maximumZoomScale) {
         maxScale = maximumZoomScale;
     }
+
+    public void setOnActive(boolean active) {
+        if (mEventEmitter != null) {
+            WritableMap params = Arguments.createMap();
+            params.putBoolean("value", active);
+            mEventEmitter.receiveEvent(getId(), "onAc
eth-jashan commented 1 week ago

@felix-phil , was curios whether this fully works or there are some issues in this patch

felix-phil commented 1 week ago

I currently use it on a production project. onActive prop to know when the pinch is going on so as to deactivate all other animation gestures. So, it works.