New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(material/slider): incorrectly attributing touches for multiple touch events #22615
fix(material/slider): incorrectly attributing touches for multiple touch events #22615
Conversation
I couldn't verify this PR. Steps to reproduce:
|
src/material/slider/slider.ts
Outdated
if (oldValue != this.value) { | ||
this._emitInputEvent(); | ||
this._touchId = isTouchEvent(event) ? | ||
event.touches[event.touches.length - 1]?.identifier : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this doesn't work as intended, if the touches are not all released in the opposite order as they are started
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only the touchstart
though, after this the order of events doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but here, we get the touch id. I'm not sure if your assumption, that the last touch in the touches list is "our" touch, is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a console.log(this._touchId); in line 650 to verify the ID, and when I am repeating my steps from my comment [1], I get the output:
0
1
1
That means, the middle slider listens on the same ID as the right slider
[1] #22615 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was working on it, I tried logging out the identifiers and it seemed like they were being added sequentially any time you tap with a different finger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just looked at some code which I implemented for my job. It's simulating a touch device (uinput) on linux.
There, I also have to define the identifier that is used for the touch.
My assumption (which I verify with my code from work) is, that the identifier in the touch event (js in the browser) is given from the touch device (driver) and not from the browser.
That would then explain why it works differently on android and the iPhone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking into it, I'll go with a modified version of your proposal for now and we can iterate on it if it ends up breaking something.
Also yeah, it's weird that there isn't a standard way for the identifiers to be generated. I noticed that the Chrome dev tools has a different way of doing it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test your implementation this evening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've tested on android with firefox and chrome.
On both devices, multitouch works now as expected, including the scenario that was not working before.
Great!
Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay, thank you for verifying 🎉
Regarding the issue mentioned above, I couldn't reproduce the issue with step 6. I tried following the instructions, but it worked as expected. Here's a recording from my device: RPReplay_Final1619974289.MP4 |
Well, yes I agree, that looks as it should. What device/browser are you using? Maybe the touch IDs are always increasing on your setup? |
I've testing it on an iPhone 7 running iOS 14.4. |
@crisbeto Are you using Safari? Could you maybe try to reproduce my issue with chrome on the IPhone? |
Yes, I was testing on Safari, but I just tried Chrome and it worked the same. My understanding is that Chrome on iOS is basically a Safari web view due to some Apple policy that doesn't allow custom web browsers. |
ec732bc
to
8272516
Compare
Some general question: |
I believe that the only other place where this would be a problem is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…uch events `mat-slider` is set up so that it binds global `touchmove` and `touchend` events after dragging starts so that the user can drag while not keeping their finger right on top of the slider. The problem is that currently we only use the first touch from the list of touches which means that if the user is dragging more than one slider on a multi-touch device, they'll all have the same value. These changes add some logic that attributes the events to the slider that started the dragging sequence. Fixes angular#22614.
8272516
to
63a5cd5
Compare
Hey, I just want to check back what's blocking this PR from being merged. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
mat-slider
is set up so that it binds globaltouchmove
andtouchend
events after dragging starts so that the user can drag while not keeping their finger right on top of the slider. The problem is that currently we only use the first touch from the list of touches which means that if the user is dragging more than one slider on a multi-touch device, they'll all have the same value.These changes add some logic that attributes the events to the slider that started the dragging sequence.
Note: I haven't included unit tests for this, because we don't seem to have any tests for touch events on the slider (not sure if there are historical reasons for this). I've been testing the fix against a real touch device.
Fixes #22614.