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

Adds experimental event component responder surfaces #15228

Merged
merged 8 commits into from
Mar 27, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Mar 27, 2019

Note: this is for an experimental event API that we're testing out internally at Facebook.

This PR adds Press and Hover responder surfaces, some additional event context APIs and fixes some bugs surfaced from the additional Press tests added.

#15036
#15112
#15150
#15168
#15179

This PR also adds tests that validate the triggering of event responder handleEvent function.

let keyPressEventListener = props.onPress;

// Wrap listener with prevent default behaviour, unless
// we are dealing with an anchor
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are anchors excluded?

case 'touchstart':
// Touch events are for Safari, which lack pointer event support.
if (!state.isPressed && !context.isTargetOwned(eventTarget)) {
// We bail out of polyfilling anchor tags
Copy link
Contributor

Choose a reason for hiding this comment

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

This could also do with explanation

state.isPressed = false;
state.isLongPressed = false;
// Prevent mouse events from firing
(event: any).preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC this can also prevent subsequent non-mouse events from firing, like focus. I didn't rely on preventDefault in RNW for this reason and relied on ignoring mouse events that occur within a period after a touch event (which also doesn't require relying on non-passive touch events) - https://github.com/necolas/react-native-web/blob/0.11.2/packages/react-native-web/src/modules/ResponderEventPlugin/index.js#L65-L71.

return;
}
// Ignore right-clicks
if (event.button === 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding event.button === 1 will also ignore middle-clicks, e.g., on a scroll wheel

const {eventTarget, eventType, event} = context;

switch (eventType) {
case 'keydown': {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should consider making keyboards trigger pressin, pressout, press, and even longpress events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do this at a later point, in a follow up.

@facebook facebook deleted a comment from sizebot Mar 27, 2019
@sizebot
Copy link

sizebot commented Mar 27, 2019

ReactDOM: size: 🔺+0.1%, gzip: 🔺+0.3%

Details of bundled changes.

Comparing: 80f8b0d...cf5b523

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.3% +0.3% 810.26 KB 812.66 KB 183.72 KB 184.2 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.3% 105.11 KB 105.18 KB 33.97 KB 34.07 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 108.08 KB 108.16 KB 34.63 KB 34.67 KB UMD_PROFILING
react-dom.development.js +0.3% +0.3% 804.65 KB 807.05 KB 182.12 KB 182.61 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 105.08 KB 105.16 KB 33.47 KB 33.52 KB NODE_PROD
react-dom.profiling.min.js +0.1% +0.2% 108.19 KB 108.26 KB 34.08 KB 34.15 KB NODE_PROFILING
ReactDOM-dev.js +0.3% +0.2% 829.31 KB 831.75 KB 183.83 KB 184.26 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.7% 🔺+0.7% 328.59 KB 330.98 KB 60.49 KB 60.9 KB FB_WWW_PROD
ReactDOM-profiling.js -0.9% -0.6% 340.33 KB 337.36 KB 62.63 KB 62.26 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.3% +0.3% 810.6 KB 813 KB 183.87 KB 184.34 KB UMD_DEV
react-dom-unstable-fire.production.min.js 🔺+0.1% 🔺+0.3% 105.12 KB 105.2 KB 33.98 KB 34.08 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js +0.1% +0.1% 108.1 KB 108.17 KB 34.63 KB 34.68 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.3% +0.3% 804.99 KB 807.39 KB 182.26 KB 182.75 KB NODE_DEV
react-dom-unstable-fire.production.min.js 🔺+0.1% 🔺+0.1% 105.1 KB 105.18 KB 33.48 KB 33.53 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js +0.1% +0.2% 108.2 KB 108.28 KB 34.09 KB 34.16 KB NODE_PROFILING
ReactFire-dev.js +0.3% +0.3% 828.52 KB 830.96 KB 183.7 KB 184.17 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.9% 🔺+1.0% 317.25 KB 320.08 KB 58.16 KB 58.72 KB FB_WWW_PROD
ReactFire-profiling.js -0.7% -0.1% 328.84 KB 326.41 KB 60.17 KB 60.09 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 9.95 KB 9.95 KB 3.66 KB 3.66 KB UMD_PROD
react-dom-test-utils.production.min.js 0.0% -0.0% 9.73 KB 9.73 KB 3.59 KB 3.59 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js +0.3% +0.3% 60.53 KB 60.74 KB 15.8 KB 15.84 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.69 KB 10.69 KB 3.67 KB 3.66 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js +0.3% +0.3% 60.2 KB 60.41 KB 15.67 KB 15.72 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.42 KB 10.42 KB 3.57 KB 3.56 KB NODE_PROD
ReactDOMUnstableNativeDependencies-dev.js +0.3% +0.3% 58.68 KB 58.88 KB 14.85 KB 14.89 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 45.67 KB 45.67 KB 10.56 KB 10.56 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.1% 1.21 KB 1.21 KB 705 B 706 B UMD_PROD

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events.development.js n/a n/a 0 B 1.16 KB 0 B 618 B UMD_DEV
react-events.production.min.js n/a n/a 0 B 682 B 0 B 431 B UMD_PROD
react-events.production.min.js 0.0% 🔺+0.3% 512 B 512 B 353 B 354 B NODE_PROD
react-events-press.development.js n/a n/a 0 B 9.92 KB 0 B 2.42 KB UMD_DEV
react-events-press.production.min.js n/a n/a 0 B 4.08 KB 0 B 1.41 KB UMD_PROD
react-events-press.development.js n/a n/a 0 B 9.75 KB 0 B 2.38 KB NODE_DEV
react-events-press.production.min.js n/a n/a 0 B 3.91 KB 0 B 1.35 KB NODE_PROD
ReactEventsPress-dev.js n/a n/a 0 B 9.97 KB 0 B 2.41 KB FB_WWW_DEV
ReactEventsPress-prod.js n/a n/a 0 B 8.18 KB 0 B 1.74 KB FB_WWW_PROD
react-events-hover.development.js n/a n/a 0 B 4.73 KB 0 B 1.32 KB UMD_DEV
react-events-hover.production.min.js n/a n/a 0 B 2.12 KB 0 B 903 B UMD_PROD
react-events-hover.development.js n/a n/a 0 B 4.56 KB 0 B 1.28 KB NODE_DEV
react-events-hover.production.min.js n/a n/a 0 B 1.95 KB 0 B 845 B NODE_PROD
ReactEventsHover-dev.js n/a n/a 0 B 4.53 KB 0 B 1.29 KB FB_WWW_DEV
ReactEventsHover-prod.js n/a n/a 0 B 3.76 KB 0 B 1.05 KB FB_WWW_PROD

Generated by 🚫 dangerJS

@trueadm
Copy link
Contributor Author

trueadm commented Mar 27, 2019

I checked manually and this PR does not add any size compared to master. The results.json in master needs updating.

@trueadm trueadm merged commit 669cafb into facebook:master Mar 27, 2019
@trueadm trueadm deleted the context-update branch March 27, 2019 23:42
Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

Let's not land without review. If you want to move fast, we should create a new build that we can put behind a flag since this currently goes to real prod it can break FB.

@sebmarkbage
Copy link
Collaborator

We don't compare against the results.json file but a rebuilt version. I tested locally and the (small) build increase shown by sizebot above seems legit.

@trueadm
Copy link
Contributor Author

trueadm commented Mar 28, 2019

@sebmarkbage I saw it was approved earlier, we also spoke about it earlier too. None of these code paths should get used on FB, but I’ll be sure to sanity check this.

The size difference doesn’t make sense. If I remove the changes in this PR and build, I still get 0.3% increase locally.

@sebmarkbage
Copy link
Collaborator

I checked out this commit built and then checked out the previous commit and built that. Then compared the two bundles.

I never compare against the checked in JSON. That one never matches up.

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

Successfully merging this pull request may close these issues.

5 participants