Skip to content

TouchableOpacity triggering <input> and <TextInput> #1164

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
bcpugh opened this issue Nov 5, 2018 · 5 comments
Closed

TouchableOpacity triggering <input> and <TextInput> #1164

bcpugh opened this issue Nov 5, 2018 · 5 comments

Comments

@bcpugh
Copy link

bcpugh commented Nov 5, 2018

The problem
On safari mobile, TouchableOpacity will trigger another component at the same location when changing views (if second component is an "<input>" or "<TextInput>").

<input> example provided below. Similar behavior for a TextInput at same location; however, unable to reproduce succinctly in sandbox (using Redux Form for this implementation).

How to reproduce
https://codesandbox.io/s/6njwzqojnr
(I tried to minimize redux / router code).
If you load on mobile safari on iPhone and click the upper left of the first component (i.e.TouchableOpacity, blue) it will trigger the second component (i.e. <input>, red).

Steps to reproduce:

  1. TouchableOpacity overlapping where in second view, w/ onPress triggers view change
  2. User touches TouchableOpacity in the overlapping location
  3. gets triggered unintentionally. Longer presses increase frequency of unexpected behavior

Expected behavior
Expected touchstart and touchend events only.
(Using safari devtools hooked up to my iPhone, recorded events are: touchstart, touchend, mouseover, mousemove, mousedown, mouseup, and click (<-- targets the input file). In my app, the final click gets fired twice, even.

RNW: 0.9.6
RN: 0.57.4
Browser: Safari (iOS12, iPhone 7)

@hushicai
Copy link
Contributor

hushicai commented Nov 15, 2018

i think this is caused by mouse event, even though the emulated mouse events filter time is now 1000ms from c3cbd53, it is still happen sometimes in some browser, such as Tencent QQ.

my solution is to disable the mouse event if in touch screen.

if ('ontouchstart' in window) {
  let stop = e => {
    return e.stopPropagation();
  };

  document.body.addEventListener('mousemove', stop, true);
  document.body.addEventListener('mousedown', stop, true);
  document.body.addEventListener('mouseup', stop, true);
}

mouse event make no sense in mobile.

and if app is runnning on pc, mouse event will not be disabled because of 'ontouchstart' in window.

@necolas
Copy link
Owner

necolas commented Nov 15, 2018

There are PC with touch screen so the single window check is not safe

@hushicai
Copy link
Contributor

ok, but it works indeed.

the problem is that touch and mouse happened together.

if touch is supported on a device, then ignore mouse event; otherwise, use mouse event.

@tafelito
Copy link

I'm having a similar issue I think, where the onPress doesn't get called, most of the time, but in my case it doesn't matter what the first child is, and it happens if I'm in chrome desktop, but not in chrome mobile (responsive) neither in safari.
What I notice is that when it works, is because I try no to move the mouse, just click. If I slightly move the mouse while clicking, then the onPress event doesn't fire

related to #1124

@necolas
Copy link
Owner

necolas commented Jan 3, 2019

Closing this issue so we can coordinate findings and solutions in #1219

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

4 participants