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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import invariant from 'shared/invariant';

import {dispatchEvent} from './ReactFabricEventEmitter';

import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
import {
DefaultEventPriority,
DiscreteEventPriority,
} from 'react-reconciler/src/ReactEventPriorities';

// Modules provided by RN:
import {
Expand All @@ -48,6 +51,9 @@ const {
measure: fabricMeasure,
measureInWindow: fabricMeasureInWindow,
measureLayout: fabricMeasureLayout,
unstable_DefaultEventPriority: FabricDefaultPriority,
unstable_DiscreteEventPriority: FabricDiscretePriority,
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
} = nativeFabricUIManager;

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
Expand Down Expand Up @@ -343,6 +349,20 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
}

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

if (currentEventPriority != null) {
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.

case FabricDiscretePriority:
return DiscreteEventPriority;
case FabricDefaultPriority:
default:
return DefaultEventPriority;
}
}

return DefaultEventPriority;
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ declare var nativeFabricUIManager: {
isJsResponder: boolean,
blockNativeResponder: boolean,
) => void,
unstable_DefaultEventPriority: number,
unstable_DiscreteEventPriority: number,
unstable_getCurrentEventPriority: () => number,
...
};

Expand Down