Skip to content

Commit

Permalink
fix: pinch gesture velocity expressed in scale factor per second on a…
Browse files Browse the repository at this point in the history
…ndroid (#3072)

## Description

Pinch gesture velocity should be expressed in scale factor per second on
android (just like on iOS
[here](https://developer.apple.com/documentation/uikit/uipinchgesturerecognizer/1622233-velocity?language=objc)).
I have changed delta to be in seconds instead of ms when calculating the
velocity.

<!--
Description and motivation for this PR.

Include 'Fixes #<number>' if this is fixing some issue.
-->

## Test plan

I've compared that manually on iOS and android simulator.

<!--
Describe how did you test this change here.
-->
  • Loading branch information
coado authored Sep 2, 2024
1 parent f1e8f97 commit cdc2e60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PinchGestureHandler : GestureHandler<PinchGestureHandler>() {
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ 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;
}

/**
* Return the event time of the current event being processed.
*
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/gesture-handlers/pinch-gh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/gestures/pinch-gesture.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down

0 comments on commit cdc2e60

Please sign in to comment.