mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[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
This commit is contained in:
@@ -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 {
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
case FabricDiscretePriority:
|
||||
return DiscreteEventPriority;
|
||||
case FabricDefaultPriority:
|
||||
default:
|
||||
return DefaultEventPriority;
|
||||
}
|
||||
}
|
||||
|
||||
return DefaultEventPriority;
|
||||
}
|
||||
|
||||
|
||||
3
scripts/flow/react-native-host-hooks.js
vendored
3
scripts/flow/react-native-host-hooks.js
vendored
@@ -184,6 +184,9 @@ declare var nativeFabricUIManager: {
|
||||
isJsResponder: boolean,
|
||||
blockNativeResponder: boolean,
|
||||
) => void,
|
||||
unstable_DefaultEventPriority: number,
|
||||
unstable_DiscreteEventPriority: number,
|
||||
unstable_getCurrentEventPriority: () => number,
|
||||
...
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user