Skip to content

Commit 1a3f1af

Browse files
authored
[React Native] Fabric get current event priority (#21553)
* 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
1 parent e6be2d5 commit 1a3f1af

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import invariant from 'shared/invariant';
2525

2626
import {dispatchEvent} from './ReactFabricEventEmitter';
2727

28-
import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
28+
import {
29+
DefaultEventPriority,
30+
DiscreteEventPriority,
31+
} from 'react-reconciler/src/ReactEventPriorities';
2932

3033
// Modules provided by RN:
3134
import {
@@ -48,6 +51,9 @@ const {
4851
measure: fabricMeasure,
4952
measureInWindow: fabricMeasureInWindow,
5053
measureLayout: fabricMeasureLayout,
54+
unstable_DefaultEventPriority: FabricDefaultPriority,
55+
unstable_DiscreteEventPriority: FabricDiscretePriority,
56+
unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
5157
} = nativeFabricUIManager;
5258

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

345351
export function getCurrentEventPriority(): * {
352+
const currentEventPriority = fabricGetCurrentEventPriority
353+
? fabricGetCurrentEventPriority()
354+
: null;
355+
356+
if (currentEventPriority != null) {
357+
switch (currentEventPriority) {
358+
case FabricDiscretePriority:
359+
return DiscreteEventPriority;
360+
case FabricDefaultPriority:
361+
default:
362+
return DefaultEventPriority;
363+
}
364+
}
365+
346366
return DefaultEventPriority;
347367
}
348368

scripts/flow/react-native-host-hooks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ declare var nativeFabricUIManager: {
184184
isJsResponder: boolean,
185185
blockNativeResponder: boolean,
186186
) => void,
187+
unstable_DefaultEventPriority: number,
188+
unstable_DiscreteEventPriority: number,
189+
unstable_getCurrentEventPriority: () => number,
187190
...
188191
};
189192

0 commit comments

Comments
 (0)