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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved input handling #228

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Improved input handling #228

wants to merge 12 commits into from

Conversation

aleclarson
Copy link
Collaborator

Add the RCTWindow class that improves upon the current input handling logic.

Users can opt-in by using RCTWindow in place of NSWindow. If they don't, they'll continue to use the (flawed) RCTTouchHandler logic.

Event handling in RCTWindow is different in the following ways:

  • Skip touchStart events that target a focused NSTextView

  • Emit mouseOut event when the mouse leaves the RCTWindow

  • Emit touchCancel event when a "touch" leaves the RCTWindow

  • Support mouseMove events (which can be coalesced)

  • Emit mouseMove event right after mouseUp events

  • Blur the focused NSTextView when clicking outside it

  • Support rightClick events

  • Add altKey, ctrlKey, metaKey, and shiftKey properties to JS mouse events

  • Use convertPoint:toView: to compute the relative mouse location

In the future, I might try updating RCTTouchHandler with the same logic that RCTWindow has. That's what I tried originally, but I ran into issues between NSGestureRecognizer and NSTextView.

Other changes

  • rename mouseEnter to mouseOver (to align with browsers)
  • rename mouseLeave to mouseOut (to align with browsers)

In the future, I might implement the mouseEnter and mouseLeave events properly (using the JS event system).

The "mouseEnter" event in browsers does not bubble, while "mouseOver" does.
@aleclarson aleclarson requested a review from ptmt February 19, 2019 18:07
@aleclarson aleclarson force-pushed the window branch 2 times, most recently from 952a202 to 778cd07 Compare February 19, 2019 19:10
Copy link
Owner

@ptmt ptmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that, thanks for a huge amount of effort!

Libraries/Components/View/ReactNativeViewAttributes.js Outdated Show resolved Hide resolved
@aleclarson aleclarson force-pushed the window branch 2 times, most recently from b347bbb to 5a1de46 Compare February 23, 2019 16:29
The "mouseLeave" event in browsers does not bubble, while "mouseOut" does.
By subclassing NSWindow and overriding the "sendEvent:" method, we can avoid using the NSGestureRecognizer class, which seems to cause issues with NSTextView event handling.

The RCTWindow class reimplements input event handling, which solves the following issues:

  - Skip "touchStart" events that target a focused NSTextView

  - Emit "mouseOut" event when the mouse leaves the RCTWindow

  - Emit "touchCancel" when the mouse leaves the RCTWindow

  - Support "mouseMove" events (which can be coalesced)

  - Emit "mouseMove" event right after "mouseUp" events

  - Blur the focused NSTextView when clicking outside it

  - Support "contextMenu" events

  - Add "altKey", "ctrlKey", "metaKey", and "shiftKey" properties to JS mouse events

  - Use "convertPoint:toView:" to compute the relative mouse location
These new calculations match the UIManager#measure method.
The RCTRootContentView "hitTest:" method now flips the Y-axis of whatever point is passed to it, instead of relying on the caller to do it.

Also, the `passThroughTouches` property of RCTRootView now works as expected.
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

Successfully merging this pull request may close these issues.

2 participants