question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting pointerEvents to "box-none" prevents triggering onTouch* and onLayout events on the element

See original GitHub issue

Describe the bug

Setting pointerEvents: 'box-none' on a View prohibits triggering onTouch* or onLayout events on the View. This behavior differs from React Native itself. This Expo Snack showcases that pressing the child Pressable of a <View pointerEvents="box-none" /> still triggers the onTouchStart and onTouchEnd events. This change in behavior, which appears to differ from React Native, began in with 7.2.0 due to changes in https://github.com/callstack/react-native-testing-library/pull/655.

Expected behavior

Invoking fireEvent.trigger(viewWithPointerEventsBoxNone, "onTouchStart") results in triggering the View’s onTouchStart handler.

Similarly, invoking fireEvent.trigger(viewWithPointerEventsBoxNone, "onLayout") results in triggering the View’s onLayout handler.

Steps to Reproduce

  1. Press the “Press me” text in the Expo Snack to observe the expected behavior.
  2. Clone the reproduction case, specifically the pointerevents-box-none-and-ontouchevents branch.
  3. npm install
  4. npm run test

Screenshots

n/a

Versions

  npmPackages:
    @testing-library/react-native: ^9.0.0 => 9.0.0
    react: 17.0.2 => 17.0.2
    react-native: 0.66.4 => 0.66.4
    react-test-renderer: 17.0.2 => 17.0.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dcalhouncommented, Jan 24, 2022

I opened https://github.com/callstack/react-native-testing-library/pull/906 for consideration to resolve this issue.

0reactions
dcalhouncommented, Jan 21, 2022

Is it possible onTouch* are only available with Fabric renderer?

No, I do not believe so. The failing test case I provided for this issue originates from the WordPress Gutenberg project, which utilized onTouch* alongside of React Native 0.61.5 at the time. I do not believe React Native 0.61.5 leveraged the Fabric renderer.

In this light we should extend our pointer events support to these events. onLayout should work as well, yes.

👍🏻 Great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way in which I can ignore touch events on Text in ...
If anyone is looking for the solution in normal React (not React Native), you can simply set the css to pointer-events: none for...
Read more >
pointer-events - CSS: Cascading Style Sheets - MDN Web Docs
The pointer-events CSS property sets under what circumstances (if any) a particular graphic element can become the target of pointer events.
Read more >
View - React Native
'none' : The View is never the target of touch events. 'box-none' : The View is never the target of touch events but...
Read more >
Tumult Hype Documentation
Tumult Hype affords ways to trigger actions in response to mouse events such as clicks, ... By default, all Hype elements have pointer...
Read more >
Pointer Events - W3C
While Pointer Events are sourced from a variety of input devices, they are not defined as being generated from some other set of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found