From 6f523500f059dbca700f86a804a854fe83ffb36c Mon Sep 17 00:00:00 2001 From: Dawid Date: Tue, 27 Aug 2024 12:26:28 +0200 Subject: [PATCH 1/4] calculating velocity scale factor base on delta in seconds on android --- .../com/swmansion/gesturehandler/core/PinchGestureHandler.kt | 3 ++- .../swmansion/gesturehandler/core/ScaleGestureDetector.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt b/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt index 55bd282eda..b5e79b3fc2 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt @@ -23,7 +23,8 @@ class PinchGestureHandler : GestureHandler() { override fun onScale(detector: ScaleGestureDetector): Boolean { val prevScaleFactor: Double = scale scale *= detector.scaleFactor.toDouble() - val delta = detector.timeDelta + val delta = detector.timeDeltaSeconds + if (delta > 0) { velocity = (scale - prevScaleFactor) / delta } diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java b/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java index 8761b9ea2d..e05b730a26 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +++ b/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java @@ -547,6 +547,10 @@ public long getTimeDelta() { return mCurrTime - mPrevTime; } + public double getTimeDeltaSeconds() { + return (double)this.getTimeDelta() / 1000; + } + /** * Return the event time of the current event being processed. * From 782777d6c88ffda04001f7661582b5bc930289cb Mon Sep 17 00:00:00 2001 From: Dawid Date: Tue, 27 Aug 2024 12:35:01 +0200 Subject: [PATCH 2/4] docs update --- docs/docs/gestures/pinch-gesture.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/gestures/pinch-gesture.md b/docs/docs/gestures/pinch-gesture.md index 4ccdf3dbba..96efe3598d 100644 --- a/docs/docs/gestures/pinch-gesture.md +++ b/docs/docs/gestures/pinch-gesture.md @@ -85,7 +85,7 @@ The scale factor relative to the points of the two touches in screen coordinates ### `velocity` -Velocity of the pan gesture the current moment. The value is expressed in point units per second. +Velocity of the pan gesture the current moment. The value is expressed in scale factor per second. ### `focalX` From 90373eca47d815fb87dbd691c84db5714150afaf Mon Sep 17 00:00:00 2001 From: Dawid Date: Tue, 27 Aug 2024 12:45:19 +0200 Subject: [PATCH 3/4] getTimeDeltaSeconds comment --- .../swmansion/gesturehandler/core/ScaleGestureDetector.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java b/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java index e05b730a26..816e7798da 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +++ b/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java @@ -547,6 +547,12 @@ public long getTimeDelta() { return mCurrTime - mPrevTime; } + /** + * Return the time difference in seconds between the previous + * accepted scaling event and the current scaling event. + * + * @return Time difference since the last scaling event in seconds. + */ public double getTimeDeltaSeconds() { return (double)this.getTimeDelta() / 1000; } From bc06720994816e318121492566ca600f0beb5dba Mon Sep 17 00:00:00 2001 From: Dawid Date: Tue, 27 Aug 2024 12:59:01 +0200 Subject: [PATCH 4/4] legacy docs update --- docs/docs/gesture-handlers/pinch-gh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/gesture-handlers/pinch-gh.md b/docs/docs/gesture-handlers/pinch-gh.md index 55fac39ad2..e12e97438d 100644 --- a/docs/docs/gesture-handlers/pinch-gh.md +++ b/docs/docs/gesture-handlers/pinch-gh.md @@ -34,7 +34,7 @@ The scale factor relative to the points of the two touches in screen coordinates ### `velocity` -Velocity of the pan gesture the current moment. The value is expressed in point units per second. +Velocity of the pan gesture the current moment. The value is expressed in scale factor per second. ### `focalX`