Bug 58862 - Pinch Gesture Recognizer Scale property not working correctly
Summary: Pinch Gesture Recognizer Scale property not working correctly
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 59508 ()
Depends on:
Blocks:
 
Reported: 2017-08-17 20:24 UTC by Valerii Rotermel
Modified: 2018-03-05 16:02 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Valerii Rotermel 2017-08-17 20:24:43 UTC
**Overview:**
PinchGestureUpdatedEventArgs property Scale do not gets correct value.

**Steps to Reproduce:**
1. Add any container like StackLayot
2. Add some Image, set Source property equal to the URI-image
3. Add PinchGestureRecognizer 
4. Add Label to represent current Scale value.
5. Run applicaytion and try to "Zoom In"(Pinch). 

**Actual Results:**
Scale property getting not correct values:
- 1.019457
- 1.021916
- 1.020922

**Expected Results:**
Scale value should always increase or decrease smoothly.

**Build Date & Platform:**

   Xamarin.Forms 2.3.4.247
   Mono.Droid: v4.0.30319
   Xamarin.Forms.Platform.Android: v4.0.30319
Comment 1 Valerii Rotermel 2017-08-17 20:39:18 UTC
Video with bug could be found here: https://drive.google.com/file/d/0B1lVIKDv7tWSMFhvMEF4Rm1nR0U/view?usp=sharing
Real case how it could affect Image-zooming functional here: 
https://drive.google.com/file/d/0B1lVIKDv7tWSQ2Q3ZmFYTXdiNlk/view?usp=sharing
Comment 2 Jimmy [MSFT] 2017-08-23 17:07:28 UTC
The PinchGestureUpdatedEventArgs.Scale value is a delta from the last event in the current gesture so it may not change linearly. In order to avoid the jumpiness shown in the video, you can add up the scale values so it continuously increases or decreases while the gesture runs. This is demonstrated in the PinchGestureRecognizer sample here: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/gestures/pinch/

I agree that the documentation for PinchGestureUpdatedEventArgs.Scale does not make this behavior clear so I will raise an issue with the docs team for this.

Hope this helps!
Comment 3 Valerii Rotermel 2017-09-02 11:22:43 UTC
Hi Jimmy,
Thank you for your respond. 

I've checked and tested the way where I am addinng up the scale values and it does not helps. 

I just have outputed scale properties values to ensure that it's bug on Androdid: 
- 1.019457 - first pinch step
- 1.021916 - second pinch step.
- 1.020922 - third pinch step.
 Could you please explain me where is delta from the last event in current gesture ?

Let's calculate delta from the first and second pinches from my example:
delta = 2nd - 1st
delta = 1.021916 - 1.019457  = 0.002459
Pinch result =  1 - 0.002459 = 0.997541

In my case we have 1.020922 which is not equal to calculated pinch result. 

**ALSO PLEASE NOTE**
On iOS platform this Pinch realisation is working fine without jumpiness.

Thanks, Valerii
Comment 4 Nicholas Bauer 2017-09-17 13:42:20 UTC
*** Bug 59508 has been marked as a duplicate of this bug. ***
Comment 5 Nicholas Bauer 2017-09-17 13:46:38 UTC
Documentation states that Scale is:

"The distance between the user's digits, divided by the initial distance between the user's digits in the pinch gesture."

There is no indication that this is updated since the last event, as opposed to since the start of the gesture which would be the natural reading of "initial position".


@Valerii - You'd need to multiply scale values to accumulate them.
Comment 6 Nicholas Bauer 2017-09-17 14:19:37 UTC
To make things more confusing, RelScaleTo method, which would be the natural method to use with relative scaling updates, uses 0 as "no change" and negative values to indicate smaller scale, rather than 0-1 for smaller, >1 for larger, which is how ScaleTo works.
Comment 7 Valerii Rotermel 2017-09-18 09:06:06 UTC
@Nicholas I could understand how it works, but just one thing make me confused - why same code working fine on iOS? It's makes me think that it's a bug, because this working different, but should be same. That is the point. How about this?
Comment 8 Nicholas Bauer 2017-09-19 02:25:38 UTC
@Valerii - Sadly I don't have iOS devices so can't confirm that.
Comment 9 Paul DiPietro [MSFT] 2018-03-05 16:02:18 UTC
Please open a new issue on GitHub with a reproduction project if you are still experiencing the behavior as of the latest stable release of Forms, as we use that for tracking now. Thanks.