Skip to content

Commit

Permalink
Add a host config method
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 8, 2021
1 parent 5876055 commit 0517f3d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@

import Transform from 'art/core/transform';
import Mode from 'art/modes/current';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';

import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;

const pooledTransform = new Transform();

const NO_CONTEXT = {};
Expand Down Expand Up @@ -340,6 +348,10 @@ export function shouldSetTextContent(type, props) {
);
}

export function getCurrentEventPriority() {
return DefaultLanePriority;
}

// The ART renderer is secondary to the React DOM renderer.
export const isPrimaryRenderer = false;

Expand Down
17 changes: 17 additions & 0 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
import {
isEnabled as ReactBrowserEventEmitterIsEnabled,
setEnabled as ReactBrowserEventEmitterSetEnabled,
getEventPriority,
} from '../events/ReactDOMEventListener';
import {getChildNamespace} from '../shared/DOMNamespaces';
import {
Expand All @@ -65,10 +66,18 @@ import {
enableSuspenseServerRenderer,
enableCreateEventHandleAPI,
enableScopeAPI,
enableNewReconciler,
} from 'shared/ReactFeatureFlags';
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;

export type Type = string;
export type Props = {
autoFocus?: boolean,
Expand Down Expand Up @@ -372,6 +381,14 @@ export function createTextInstance(
return textNode;
}

export function getCurrentEventPriority(): * {
const currentEvent = window.event;
if (currentEvent === undefined) {
return DefaultLanePriority;
}
return getEventPriority(currentEvent.type);
}

export const isPrimaryRenderer = true;
export const warnsIfNotActing = true;
// This initialization code may run even on server environments
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function attemptToDispatchEvent(
return null;
}

function getEventPriority(domEventName: DOMEventName) {
export function getEventPriority(domEventName: DOMEventName): * {
switch (domEventName) {
// Used by SimpleEventPlugin:
case 'cancel':
Expand Down
12 changes: 12 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ import type {
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
import {create, diff} from './ReactNativeAttributePayload';

import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';

import {dispatchEvent} from './ReactFabricEventEmitter';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;

// Modules provided by RN:
import {
ReactNativeViewConfigRegistry,
Expand Down Expand Up @@ -339,6 +347,10 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
return false;
}

export function getCurrentEventPriority(): * {
return DefaultLanePriority;
}

// The Fabric renderer is secondary to the existing React Native renderer.
export const isPrimaryRenderer = false;

Expand Down
12 changes: 12 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type {TouchedViewDataAtPoint} from './ReactNativeTypes';

import invariant from 'shared/invariant';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';

// Modules provided by RN:
import {
Expand All @@ -26,6 +27,13 @@ import {
} from './ReactNativeComponentTree';
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;

const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;

export type Type = string;
Expand Down Expand Up @@ -261,6 +269,10 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
return false;
}

export function getCurrentEventPriority(): * {
return DefaultLanePriority;
}

// -------------------
// Mutation
// -------------------
Expand Down
12 changes: 12 additions & 0 deletions packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ import {

import ReactSharedInternals from 'shared/ReactSharedInternals';
import enqueueTask from 'shared/enqueueTask';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
const {IsSomeRendererActing} = ReactSharedInternals;

import {DefaultLanePriority as DefaultLanePriority_old} from 'react-reconciler/src/ReactFiberLane.old';
import {DefaultLanePriority as DefaultLanePriority_new} from 'react-reconciler/src/ReactFiberLane.new';

const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;

type Container = {
rootID: string,
children: Array<Instance | TextInstance>,
Expand Down Expand Up @@ -391,6 +399,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {

resetAfterCommit(): void {},

getCurrentEventPriority() {
return DefaultLanePriority;
},

now: Scheduler.unstable_now,

isPrimaryRenderer: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const afterActiveInstanceBlur = $$$hostConfig.afterActiveInstanceBlur;
export const preparePortalMount = $$$hostConfig.preparePortalMount;
export const prepareScopeUpdate = $$$hostConfig.preparePortalMount;
export const getInstanceFromScope = $$$hostConfig.getInstanceFromScope;
export const getCurrentEventPriority = $$$hostConfig.getCurrentEventPriority;

// -------------------
// Test selectors
Expand Down

0 comments on commit 0517f3d

Please sign in to comment.