@samitouri / QOS-React / commits / 1a3f1afbd3

[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

Samuel Susla committed Jun 8, 2021 at 17:26 UTC 1a3f1afbd3cf815d4e55628cd7d84ef20171bab8
2 files changed +24 -1
packages/react-native-renderer/src/ReactFabricHostConfig.js
+21 -1
@@ -25,7 +25,10 @@ import invariant from 'shared/invariant';
25
26 import {dispatchEvent} from './ReactFabricEventEmitter';
27
28 -import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities';
28 +import {
29 + DefaultEventPriority,
30 + DiscreteEventPriority,
31 +} from 'react-reconciler/src/ReactEventPriorities';
32
33 // Modules provided by RN:
34 import {
@@ -48,6 +51,9 @@ const {
51 measure: fabricMeasure,
52 measureInWindow: fabricMeasureInWindow,
53 measureLayout: fabricMeasureLayout,
54 + unstable_DefaultEventPriority: FabricDefaultPriority,
55 + unstable_DiscreteEventPriority: FabricDiscretePriority,
56 + unstable_getCurrentEventPriority: fabricGetCurrentEventPriority,
57 } = nativeFabricUIManager;
58
59 const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
@@ -343,6 +349,20 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
349 }
350
351 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 +
366 return DefaultEventPriority;
367 }
368
scripts/flow/react-native-host-hooks.js
+3
@@ -184,6 +184,9 @@ declare var nativeFabricUIManager: {
184 isJsResponder: boolean,
185 blockNativeResponder: boolean,
186 ) => void,
187 + unstable_DefaultEventPriority: number,
188 + unstable_DiscreteEventPriority: number,
189 + unstable_getCurrentEventPriority: () => number,
190 ...
191 };
192