Skip to content

Commit

Permalink
[React Native] Fabric get current event priority (#21553)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sammy-SC authored Jun 8, 2021
1 parent e6be2d5 commit 1a3f1af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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) {
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

0 comments on commit 1a3f1af

Please sign in to comment.