Skip to content

[React Native] Fabric get current event priority #21553

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

Merged

Conversation

sammy-SC
Copy link
Contributor

@sammy-SC sammy-SC commented May 24, 2021

Summary

Replace default implementation of getCurrentEventPriority with a call to Fabric to check current event's priority.

@sizebot
Copy link

sizebot commented May 24, 2021

Comparing: 5aa0c56...f170db8

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 127.29 kB 127.29 kB = 40.81 kB 40.81 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 130.11 kB 130.11 kB = 41.75 kB 41.75 kB
facebook-www/ReactDOM-prod.classic.js = 404.72 kB 404.72 kB = 74.90 kB 74.90 kB
facebook-www/ReactDOM-prod.modern.js = 393.27 kB 393.27 kB = 73.09 kB 73.09 kB
facebook-www/ReactDOMForked-prod.classic.js = 404.72 kB 404.72 kB = 74.90 kB 74.90 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against f170db8

@sammy-SC sammy-SC force-pushed the rn-fabric-getCurrentEventPriority branch from 331f702 to 761c937 Compare May 25, 2021 10:56
@sammy-SC sammy-SC changed the title Rn fabric get current event priority Rn Fabric get current event priority May 25, 2021
@sammy-SC sammy-SC force-pushed the rn-fabric-getCurrentEventPriority branch from 23a4e33 to 61d10f9 Compare May 25, 2021 12:25
@sammy-SC sammy-SC marked this pull request as ready for review May 25, 2021 12:25
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

What about continuous priority? For things like pointer move.

@rickhanlonii rickhanlonii changed the title Rn Fabric get current event priority [React Native] Fabric get current event priority May 25, 2021
@rickhanlonii
Copy link
Member

@gaearon we're just handing discrete for now per @sebmarkbage, but we can expand as it makes sense.

@@ -343,6 +349,18 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
}

export function getCurrentEventPriority(): * {
const currentEventPriority = fabricGetCurrentEventPriority();
Copy link
Member

Choose a reason for hiding this comment

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

What if fabricGetCurrentEventPriority is not defined or nativeFabricUIManager doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if fabricGetCurrentEventPriority is not defined, Fabric returns undefined.

We guarantee existence of nativeFabricUIManager. If it doesn't exist, something is very wrong.

@@ -343,6 +349,18 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
}

export function getCurrentEventPriority(): * {
const currentEventPriority = fabricGetCurrentEventPriority();

if (currentEventPriority !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

So null would be the Default priority? That's how it ends up working in DOM, but just making sure that's intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this condition here for safety. If Fabric returns undefined, which it never should, we fall back to the old behaviour.

const currentEventPriority = fabricGetCurrentEventPriority();

if (currentEventPriority !== undefined) {
switch (currentEventPriority) {
Copy link
Member

Choose a reason for hiding this comment

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

One thing we discussed is that instead of native proving priority, they could send provide the name of the event here, and in this switch we would select the priority based on event name (like DOM does).

The advantage of this approach is that we can update this map in JavaScript without needing a native app change, and the source of truth for "event name to event priority" lives inside React (leaving us free to change the model cheaply). The disadvantage is that we'd need to maintain the map here for all React Native platforms, but as soon as we change the model we would need to maintain an event priority to new model priority map anyway.

@sebmarkbage @acdlite what do you think about those two approaches?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: sending event name of event

This doesn't work well with event priority deduction that we have implemented in Fabric.

I do have a somewhat hybrid system in mind that would combine event priority deduction with event priority map in JavaScript. I didn't want to overcomplicate the initial implementation and learn from this before making the next step.

The APIs are still marked as "unstable" to make it clear we are still experimenting with it.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request May 25, 2021
Summary:
Changelog: [internal]

Use getter function instead of accessing ivar. This makes for clearer APIs.

React part is implemented in facebook/react#21553

Reviewed By: JoshuaGross

Differential Revision: D28675372

fbshipit-source-id: cf99f8482067bfc0fd57d39fda9656abd665bb69
@rickhanlonii rickhanlonii merged commit 1a3f1af into facebook:master Jun 8, 2021
@sammy-SC sammy-SC deleted the rn-fabric-getCurrentEventPriority branch June 9, 2021 08:21
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jun 11, 2021
Summary:
This sync includes the following changes:
- **[c96b78e0e](facebook/react@c96b78e0e )**: Add concurrentRoot property to ReactNativeTypes ([#21648](facebook/react#21648)) //<Samuel Susla>//
- **[1a3f1afbd](facebook/react@1a3f1afbd )**: [React Native] Fabric get current event priority ([#21553](facebook/react#21553)) //<Samuel Susla>//
- **[48a11a3ef](facebook/react@48a11a3ef )**: Update next React version ([#21647](facebook/react#21647)) //<Andrew Clark>//
- **[5aa0c5671](facebook/react@5aa0c5671 )**: Fix Issue with Undefined Lazy Imports By Refactoring Lazy Initialization Order ([#21642](facebook/react#21642)) //<Sebastian Markbåge>//

Changelog:
[General][Changed] - React Native sync for revisions 0eea577...c96b78e

jest_e2e[run_all_tests]

Reviewed By: bvaughn

Differential Revision: D29029542

fbshipit-source-id: 9f2e19b4714b5697b5b846f2db8eb28c25420932
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
* Call into Fabric to get current event priority

Fix flow errors

* Prettier

* Better handle null and undefined cases

* Remove optional chaining and use ?? operator

* prettier-all

* Use conditional ternary operator

* prettier
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