Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds experimental event API scaffolding #15108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,19 @@ export function unhideInstance(instance, props) {
export function unhideTextInstance(textInstance, text): void {
// Noop
}

export function handleEventComponent(
eventResponder: ReactEventResponder,
rootContainerInstance: Container,
internalInstanceHandle: Object,
) {
// TODO: add handleEventComponent implementation
}

export function handleEventTarget(
type: string,
props: Props,
internalInstanceHandle: Object,
) {
// TODO: add handleEventTarget implementation
}
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 @@ -43,6 +43,7 @@ import {
import dangerousStyleValue from '../shared/dangerousStyleValue';

import type {DOMContainer} from './ReactDOM';
import type {ReactEventResponder} from 'shared/ReactTypes';

export type Type = string;
export type Props = {
Expand Down Expand Up @@ -793,3 +794,19 @@ export function didNotFindHydratableSuspenseInstance(
// TODO: warnForInsertedHydratedSuspense(parentInstance);
}
}

export function handleEventComponent(
eventResponder: ReactEventResponder,
rootContainerInstance: Container,
internalInstanceHandle: Object,
) {
// TODO: add handleEventComponent implementation
}

export function handleEventTarget(
type: string,
props: Props,
internalInstanceHandle: Object,
) {
// TODO: add handleEventTarget implementation
}
17 changes: 17 additions & 0 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
NativeMethodsMixinType,
ReactNativeBaseComponentViewConfig,
} from './ReactNativeTypes';
import type {ReactEventResponder} from 'shared/ReactTypes';

import {
mountSafeCallback_NOT_REALLY_SAFE,
Expand Down Expand Up @@ -417,3 +418,19 @@ export function replaceContainerChildren(
container: Container,
newChildren: ChildSet,
): void {}

export function handleEventComponent(
eventResponder: ReactEventResponder,
rootContainerInstance: Container,
internalInstanceHandle: Object,
) {
// TODO: add handleEventComponent implementation
}

export function handleEventTarget(
type: string,
props: Props,
internalInstanceHandle: Object,
) {
// TODO: add handleEventTarget implementation
}
17 changes: 17 additions & 0 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
import type {ReactEventResponder} from 'shared/ReactTypes';

import invariant from 'shared/invariant';

Expand Down Expand Up @@ -476,3 +477,19 @@ export function unhideTextInstance(
): void {
throw new Error('Not yet implemented.');
}

export function handleEventComponent(
eventResponder: ReactEventResponder,
rootContainerInstance: Container,
internalInstanceHandle: Object,
) {
// TODO: add handleEventComponent implementation
}

export function handleEventTarget(
type: string,
props: Props,
internalInstanceHandle: Object,
) {
// TODO: add handleEventTarget implementation
}
11 changes: 10 additions & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
IncompleteClassComponent,
MemoComponent,
SimpleMemoComponent,
EventTarget,
} from 'shared/ReactWorkTags';
import {
invokeGuardedCallback,
Expand Down Expand Up @@ -90,6 +91,7 @@ import {
hideTextInstance,
unhideInstance,
unhideTextInstance,
handleEventTarget,
} from './ReactFiberHostConfig';
import {
captureCommitPhaseError,
Expand Down Expand Up @@ -299,6 +301,7 @@ function commitBeforeMutationLifeCycles(
case HostText:
case HostPortal:
case IncompleteClassComponent:
case EventTarget:
// Nothing to do for these component types
return;
default: {
Expand Down Expand Up @@ -584,8 +587,8 @@ function commitLifeCycles(
return;
}
case SuspenseComponent:
break;
case IncompleteClassComponent:
case EventTarget:
break;
default: {
invariant(
Expand Down Expand Up @@ -1213,6 +1216,12 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
case IncompleteClassComponent: {
return;
}
case EventTarget: {
const newProps = finishedWork.memoizedProps;
const type = finishedWork.type.type;
handleEventTarget(type, newProps, finishedWork);
trueadm marked this conversation as resolved.
Show resolved Hide resolved
return;
}
default: {
invariant(
false,
Expand Down
13 changes: 13 additions & 0 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
SimpleMemoComponent,
LazyComponent,
IncompleteClassComponent,
EventComponent,
EventTarget,
} from 'shared/ReactWorkTags';
import {
Placement,
Expand All @@ -63,6 +65,7 @@ import {
createContainerChildSet,
appendChildToContainerChildSet,
finalizeContainerChildren,
handleEventComponent,
} from './ReactFiberHostConfig';
import {
getRootHostContainer,
Expand Down Expand Up @@ -762,6 +765,16 @@ function completeWork(
}
break;
}
case EventComponent: {
const rootContainerInstance = getRootHostContainer();
const responder = workInProgress.type.responder;
handleEventComponent(responder, rootContainerInstance, workInProgress);
trueadm marked this conversation as resolved.
Show resolved Hide resolved
break;
}
case EventTarget: {
markUpdate(workInProgress);
trueadm marked this conversation as resolved.
Show resolved Hide resolved
break;
}
default:
invariant(
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export const isPrimaryRenderer = $$$hostConfig.isPrimaryRenderer;
export const supportsMutation = $$$hostConfig.supportsMutation;
export const supportsPersistence = $$$hostConfig.supportsPersistence;
export const supportsHydration = $$$hostConfig.supportsHydration;
export const handleEventComponent = $$$hostConfig.handleEventComponent;
export const handleEventTarget = $$$hostConfig.handleEventTarget;

// -------------------
// Mutation
Expand Down
18 changes: 18 additions & 0 deletions packages/react-test-renderer/src/ReactTestHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import warning from 'shared/warning';

import type {ReactEventResponder} from 'shared/ReactTypes';

export type Type = string;
export type Props = Object;
export type Container = {|
Expand Down Expand Up @@ -260,3 +262,19 @@ export function unhideTextInstance(
): void {
textInstance.isHidden = false;
}

export function handleEventComponent(
eventResponder: ReactEventResponder,
rootContainerInstance: Container,
internalInstanceHandle: Object,
) {
// TODO: add handleEventComponent implementation
}

export function handleEventTarget(
type: string,
props: Props,
internalInstanceHandle: Object,
) {
// TODO: add handleEventTarget implementation
}
3 changes: 3 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ export const warnAboutShorthandPropertyCollision = false;
// See https://github.com/react-native-community/discussions-and-proposals/issues/72 for more information
// This is a flag so we can fix warnings in RN core before turning it on
export const warnAboutDeprecatedSetNativeProps = false;

// Experimental React Events support. Only used in www builds for now.
export const enableEventAPI = false;
6 changes: 6 additions & 0 deletions packages/shared/ReactSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export const REACT_SUSPENSE_TYPE = hasSymbol
: 0xead1;
export const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
export const REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
export const REACT_EVENT_COMPONENT_TYPE = hasSymbol
? Symbol.for('react.event')
: 0xead5;
export const REACT_EVENT_TARGET_TYPE = hasSymbol
? Symbol.for('react.event_target')
: 0xead6;

const MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
const FAUX_ITERATOR_SYMBOL = '@@iterator';
Expand Down
21 changes: 20 additions & 1 deletion packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export type ReactNode =
| ReactText
| ReactFragment
| ReactProvider<any>
| ReactConsumer<any>;
| ReactConsumer<any>
| ReactEvent
| ReactEventTarget;

export type ReactEmpty = null | void | boolean;

Expand Down Expand Up @@ -78,3 +80,20 @@ export type ReactPortal = {
export type RefObject = {|
current: any,
|};

export type ReactEventResponder = {
targetEventTypes: Array<string>,
createInitialState?: (props: Object) => Object,
handleEvent: (context: Object, props: Object, state: Object) => void,
};

export type ReactEvent = {|
$$typeof: Symbol | number,
props: null | Object,
responder: ReactEventResponder,
|};

export type ReactEventTarget = {|
$$typeof: Symbol | number,
type: string,
|};
6 changes: 5 additions & 1 deletion packages/shared/ReactWorkTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export type WorkTag =
| 15
| 16
| 17
| 18;
| 18
| 19
| 20;

export const FunctionComponent = 0;
export const ClassComponent = 1;
Expand All @@ -47,3 +49,5 @@ export const SimpleMemoComponent = 15;
export const LazyComponent = 16;
export const IncompleteClassComponent = 17;
export const DehydratedSuspenseComponent = 18;
export const EventComponent = 19;
export const EventTarget = 20;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const disableInputAttributeSyncing = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = true;
export const warnAboutDeprecatedSetNativeProps = true;
export const enableEventAPI = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
export const warnAboutShorthandPropertyCollision = false;
export const enableSchedulerDebugging = false;
export const warnAboutDeprecatedSetNativeProps = false;
export const enableEventAPI = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const enableStableConcurrentModeAPIs = false;
export const warnAboutShorthandPropertyCollision = false;
export const enableSchedulerDebugging = false;
export const warnAboutDeprecatedSetNativeProps = false;
export const enableEventAPI = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const enableStableConcurrentModeAPIs = false;
export const enableSchedulerDebugging = false;
export const warnAboutDeprecatedSetNativeProps = false;
export const disableJavaScriptURLs = false;
export const enableEventAPI = true;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function updateFlagOutsideOfReactCallStack() {
}
}

export const enableEventAPI = true;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/isValidElementType.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
REACT_SUSPENSE_TYPE,
REACT_MEMO_TYPE,
REACT_LAZY_TYPE,
REACT_EVENT_COMPONENT_TYPE,
REACT_EVENT_TARGET_TYPE,
} from 'shared/ReactSymbols';

export default function isValidElementType(type: mixed) {
Expand All @@ -36,6 +38,8 @@ export default function isValidElementType(type: mixed) {
type.$$typeof === REACT_MEMO_TYPE ||
type.$$typeof === REACT_PROVIDER_TYPE ||
type.$$typeof === REACT_CONTEXT_TYPE ||
type.$$typeof === REACT_FORWARD_REF_TYPE))
type.$$typeof === REACT_FORWARD_REF_TYPE ||
type.$$typeof === REACT_EVENT_COMPONENT_TYPE ||
type.$$typeof === REACT_EVENT_TARGET_TYPE))
);
}