Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with iOS 11.3 Mobile Safari #124

Closed
tobihagemann opened this issue Mar 30, 2018 · 14 comments
Closed

Not working with iOS 11.3 Mobile Safari #124

tobihagemann opened this issue Mar 30, 2018 · 14 comments

Comments

@tobihagemann
Copy link

It looks like the workaround

window.addEventListener( 'touchmove', function() {});

doesn't work anymore with iOS 11.3 Mobile Safari. Is there a new workaround? 馃槄 It looks like that the same issue applies to Chrome on iOS as well.

@reppners
Copy link
Collaborator

Confirmed. Relates to #77

Could only find this:
https://bugs.webkit.org/show_bug.cgi?id=182521

I'll take a look if the detection for passive event listeners works for iOS 11.3 - if it does already apply { passive:false } and it still does not work than this is going to be a fun thing for anybody trying to prevent touchmove do its thing 馃槥

@reppners reppners added the bug label Mar 30, 2018
@reppners
Copy link
Collaborator

Turns out the same workaround still applies but because Safari on iOS 11.3 enables passive event listener support it defaults to passive: true for event listeners on document level.

The fix is simple:

window.addEventListener('touchmove', function () { }, {passive: false})

But this puts the burden of feature detection of passive event listeners on the polyfill user. Maybe I should put this into another augmentation module so people who need to support Safari just import and apply a single makeItWorkOnSafari() function..

@tobihagemann
Copy link
Author

Thank you for the fast response and I can confirm that it works! 馃帀

But this puts the burden of feature detection of passive event listeners on the polyfill user.

I don't actually understand the workaround but is there anything that I have to worry/think about when using this? The "burden" you've mentioned, I don't understand what you mean by that. I guess I would have to read up on passive event listeners and their feature detection. 馃槄

@reppners
Copy link
Collaborator

I don't actually understand the workaround but is there anything that I have to worry/think about when using this? The "burden" you've mentioned, I don't understand what you mean by that. I guess I would have to read up on passive event listeners and their feature detection. 馃槄

If you need to support older browsers (e.g. previous Safari) the third parameter on document.addEventListener() would be interpreted either as capture parameter or something else unintended happens.

To correctly apply the different workarounds you now have to check for passive event listener support and act accordingly

if(supportsPassive) {
  window.addEventListener('touchmove', function () { }, {passive: false});
}
else {
  window.addEventListener( 'touchmove', function() { });
}

@tobihagemann
Copy link
Author

All right, thank you! For anyone stumbling upon this issue and wants to know how to get supportsPassive, you can test if passive event listeners are supported with:

// Test via a getter in the options object to see if the passive property is accessed
var supportsPassive = false;
try {
  var opts = Object.defineProperty({}, 'passive', {
    get: function() {
      supportsPassive = true;
    }
  });
  window.addEventListener("testPassive", null, opts);
  window.removeEventListener("testPassive", null, opts);
} catch (e) {}

Source: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection

@virendrampatil
Copy link

Hi guys,
After updating the iPad to iOS 11.3 drag drop is not working as expected. Tried the above workaround mentioned by @tobihagemann it's still not working :(

@reppners
Copy link
Collaborator

reppners commented Apr 5, 2018

Please provide exact failure description, code regarding the workaround and polyfill configuration.

@virendrampatil
Copy link

virendrampatil commented Apr 5, 2018

image
I get this error

when I scroll and then try to drag across the screen touch move event is not triggered

@reppners
Copy link
Collaborator

reppners commented Apr 5, 2018

I get this error

Is that some type-checker complaining or who does raise the error?

If you're targeting this code to Safari iOS11.3 than it's perfectly valid since its supporting the new addEventListener api.

According to can-i-use it's supported on earlier versions, too. What has changed is that document-level listeners by default apply { passive: true }.

when I scroll and then try to drag across the screen touch move event is not triggered

I'm not sure I can follow

  • Do you try to start a drag while the view is still scrolling/moving by inertia? This was never supported afaik.
  • Does a drag not even start (no drag image visible)?
  • Does drag start but you can't really move the draggable because the view is scrolling when you touchmove?

@virendrampatil
Copy link

Yes, this is the issue: drag starts but can't really move the draggable because the view is scrolling when you touchmove.

@reppners
Copy link
Collaborator

reppners commented Apr 5, 2018

Thanks for clarifying. I have an iPad at hand that is pending the update to 11.3. Will try to check locally if I can find anything helping your issue.

@reppners
Copy link
Collaborator

reppners commented Apr 5, 2018

Updated the iPad 2017 to iOS 11.3 and the demo works without problems. Note that I updated the gh-pages demo containing the new workaround a few minutes ago - please check if http://timruffles.github.io/mobile-drag-drop/demo/ works for you, too.

@sampreethD
Copy link

touchEvents are not supported by safari browsers . Please check this https://developer.mozilla.org/en-US/docs/Web/API/Touch_events

@reppners
Copy link
Collaborator

reppners commented Dec 29, 2021

Closing as this is "solved" and referenced in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants