Skip to content

Passive event listeners in Safari iOS > 11.3 #1505

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

Closed
kennethkufluk opened this issue Dec 17, 2019 · 6 comments
Closed

Passive event listeners in Safari iOS > 11.3 #1505

kennethkufluk opened this issue Dec 17, 2019 · 6 comments

Comments

@kennethkufluk
Copy link

I know Chrome implemented passive event listeners for some events in Chrome 51.
Safari did the same from iOS 11.3 onwards, but they have a different workaround:
You need to attach your event with { passive: false } if you want to be able to preventDefault.
https://bugs.webkit.org/show_bug.cgi?id=182521

Looks like React still doesn't have a decision on support for passive events.
facebook/react#6436

Until that is decided, would it be possible for touch events on the View to be non-passive by default?

(I searched around the code and issues for other mention of this and couldn't find any, but if you've solved this by some other means, I'd be very interested to learn how)

Thanks.

@necolas
Copy link
Owner

necolas commented Dec 17, 2019

Nope. This is something we need to solve in ReactDOM first; I'll bring it up again.

We're working on some ideas for completely new APIs (facebook/react#17508) but there's no schedule yet for when this will make it into a public experimental release that I could try to incorporate here.

Do you know if you're using e.preventDefault() at all with touch events? And if you can share any more context related to this request it would help me represent your needs better :)

@necolas necolas closed this as completed Dec 17, 2019
@necolas
Copy link
Owner

necolas commented Dec 17, 2019

Oh you're asking for them NOT to be passive by default! Most modern browsers are making the top-level touch listeners passive by default, so if you need to attach a non-passive touch event listener you can do so by using the native addEventListener API to attach to the view's underlying DOM node (e.g. using forwardedRef, or if that's not yet in a public release, findDOMNode)

@kennethkufluk
Copy link
Author

I’ve done that for one of our components, which swipes between images in a media gallery. It seems to work.

We also have a component for pinch-zooming, which currently acts oddly because it zooms the page at the same time. I’ll use the addEventListener fix there too.

The other touch listeners we have are for Pull-to-Dismiss and Swipe-to-Close. Again, they will need to preventDefault.

Seemed like this is a common need, so I came over here to ask the question. :) It makes total sense to wait for a new API. I hope that appears soon.

Thanks for quick reply!

@necolas
Copy link
Owner

necolas commented Dec 17, 2019

Is CSS touch-action not sufficient to prevent things like document zooming from occurring?

@kennethkufluk
Copy link
Author

As far as I understand it, Safari doesn't understand the "none" value, though that might have changed since 11.3. It might understand the "manipulation" value. I'll have to try it out. The bugs I'm looking at aren't reliably reproducible, possibly I have a race condition in the event handlers (or safari does).

@necolas
Copy link
Owner

necolas commented Dec 17, 2019

Pre-13 Safari only understands manipulation and that might be enough to avoid the browser-level zooming, pull-to-refresh, and back navigation…but yeah mobile browsers make this stuff a pain

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

No branches or pull requests

2 participants