Skip to content

Commit 57a1743

Browse files
committed
Addressed feedback and added more test coverage + warnings
Apply fiber tree traversal Apply fiber tree traversal (remove null check) Apply fiber tree traversal (remove null check)
1 parent d27dbd3 commit 57a1743

File tree

14 files changed

+593
-253
lines changed

14 files changed

+593
-253
lines changed

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ export function getChildHostContext() {
340340
return NO_CONTEXT;
341341
}
342342

343-
export function getChildHostContextForEvent() {
343+
export function getChildHostContextForEventComponent() {
344+
return NO_CONTEXT;
345+
}
346+
347+
export function getChildHostContextForEventTarget() {
344348
return NO_CONTEXT;
345349
}
346350

@@ -446,6 +450,7 @@ export function handleEventComponent(
446450
export function handleEventTarget(
447451
type: Symbol | number,
448452
props: Props,
453+
parentInstance: Container,
449454
internalInstanceHandle: Object,
450455
) {
451456
// TODO: add handleEventTarget implementation

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ import dangerousStyleValue from '../shared/dangerousStyleValue';
4545

4646
import type {DOMContainer} from './ReactDOM';
4747
import type {ReactEventResponder} from 'shared/ReactTypes';
48-
import {
49-
REACT_EVENT_COMPONENT_TYPE,
50-
REACT_EVENT_TARGET_TYPE,
51-
REACT_EVENT_TARGET_TOUCH_HIT,
52-
} from 'shared/ReactSymbols';
53-
import getElementFromTouchHitTarget from 'shared/getElementFromTouchHitTarget';
48+
import {REACT_EVENT_TARGET_TOUCH_HIT} from 'shared/ReactSymbols';
5449

5550
export type Type = string;
5651
export type Props = {
@@ -75,6 +70,7 @@ type HostContextDev = {
7570
eventData: null | {|
7671
isEventComponent?: boolean,
7772
isEventTarget?: boolean,
73+
eventTargetType?: null | Symbol | number,
7874
|},
7975
};
8076
type HostContextProd = string;
@@ -180,31 +176,46 @@ export function getChildHostContext(
180176
return getChildNamespace(parentNamespace, type);
181177
}
182178

183-
export function getChildHostContextForEvent(
179+
export function getChildHostContextForEventComponent(
184180
parentHostContext: HostContext,
185-
type: Symbol | number,
186181
): HostContext {
187182
if (__DEV__) {
188183
const parentHostContextDev = ((parentHostContext: any): HostContextDev);
189184
const {namespace, ancestorInfo} = parentHostContextDev;
190-
let eventData = null;
185+
warning(
186+
parentHostContextDev.eventData === null ||
187+
!parentHostContextDev.eventData.isEventTarget,
188+
'validateDOMNesting: React event targets must not have event components as children.',
189+
);
190+
const eventData = {
191+
isEventComponent: true,
192+
isEventTarget: false,
193+
eventTargetType: null,
194+
};
195+
return {namespace, ancestorInfo, eventData};
196+
}
197+
return parentHostContext;
198+
}
191199

192-
if (type === REACT_EVENT_COMPONENT_TYPE) {
193-
warning(
194-
parentHostContextDev.eventData === null ||
195-
!parentHostContextDev.eventData.isEventTarget,
196-
'validateDOMNesting: React event targets must not have event components as children.',
197-
);
198-
eventData = {
199-
isEventComponent: true,
200-
isEventTarget: false,
201-
};
202-
} else if (type === REACT_EVENT_TARGET_TYPE) {
203-
eventData = {
204-
isEventComponent: false,
205-
isEventTarget: true,
206-
};
207-
}
200+
export function getChildHostContextForEventTarget(
201+
parentHostContext: HostContext,
202+
type: Symbol | number,
203+
): HostContext {
204+
if (__DEV__) {
205+
const parentHostContextDev = ((parentHostContext: any): HostContextDev);
206+
const {namespace, ancestorInfo} = parentHostContextDev;
207+
warning(
208+
parentHostContextDev.eventData === null ||
209+
!parentHostContextDev.eventData.isEventComponent ||
210+
type !== REACT_EVENT_TARGET_TOUCH_HIT,
211+
'validateDOMNesting: <TouchHitTarget> cannot not be a direct child of an event component. ' +
212+
'Ensure <TouchHitTarget> is a direct child of a DOM element.',
213+
);
214+
const eventData = {
215+
isEventComponent: false,
216+
isEventTarget: true,
217+
eventTargetType: type,
218+
};
208219
return {namespace, ancestorInfo, eventData};
209220
}
210221
return parentHostContext;
@@ -238,6 +249,16 @@ export function createInstance(
238249
if (__DEV__) {
239250
// TODO: take namespace into account when validating.
240251
const hostContextDev = ((hostContext: any): HostContextDev);
252+
if (enableEventAPI) {
253+
const eventData = hostContextDev.eventData;
254+
if (eventData !== null) {
255+
warning(
256+
!eventData.isEventTarget ||
257+
eventData.eventTargetType !== REACT_EVENT_TARGET_TOUCH_HIT,
258+
'Warning: validateDOMNesting: <TouchHitTarget> must not have any children.',
259+
);
260+
}
261+
}
241262
validateDOMNesting(type, null, hostContextDev.ancestorInfo);
242263
if (
243264
typeof props.children === 'string' ||
@@ -344,14 +365,21 @@ export function createTextInstance(
344365
if (enableEventAPI) {
345366
const eventData = hostContextDev.eventData;
346367
if (eventData !== null) {
368+
warning(
369+
eventData === null ||
370+
!eventData.isEventTarget ||
371+
eventData.eventTargetType !== REACT_EVENT_TARGET_TOUCH_HIT,
372+
'Warning: validateDOMNesting: <TouchHitTarget> must not have any children.',
373+
);
347374
warning(
348375
!eventData.isEventComponent,
349376
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
350377
'Wrap the child text "%s" in an element.',
351378
text,
352379
);
353380
warning(
354-
!eventData.isEventTarget,
381+
!eventData.isEventTarget ||
382+
eventData.eventTargetType === REACT_EVENT_TARGET_TOUCH_HIT,
355383
'validateDOMNesting: React event targets cannot have text DOM nodes as children. ' +
356384
'Wrap the child text "%s" in an element.',
357385
text,
@@ -874,25 +902,13 @@ export function handleEventComponent(
874902
export function handleEventTarget(
875903
type: Symbol | number,
876904
props: Props,
905+
parentInstance: Container,
877906
internalInstanceHandle: Object,
878907
): void {
879908
if (enableEventAPI) {
880909
// Touch target hit slop handling
881910
if (type === REACT_EVENT_TARGET_TOUCH_HIT) {
882-
// Validates that there is a single element
883-
const element = getElementFromTouchHitTarget(internalInstanceHandle);
884-
if (element !== null) {
885-
// We update the event target state node to be that of the element.
886-
// We can then diff this entry to determine if we need to add the
887-
// hit slop element, or change the dimensions of the hit slop.
888-
const lastElement = internalInstanceHandle.stateNode;
889-
if (lastElement !== element) {
890-
internalInstanceHandle.stateNode = element;
891-
// TODO: Create the hit slop element and attach it to the element
892-
} else {
893-
// TODO: Diff the left, top, right, bottom props
894-
}
895-
}
911+
// TODO
896912
}
897913
}
898914
}

0 commit comments

Comments
 (0)