Skip to content

Commit 6227ff9

Browse files
authored
Add full TouchHitTarget hit slop (experimental event API) to ReactDOM (#15308)
1 parent cbe65d7 commit 6227ff9

File tree

1 file changed

+63
-16
lines changed

1 file changed

+63
-16
lines changed

src/ReactTestHostConfig.js

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import {REACT_EVENT_TARGET_TOUCH_HIT} from 'shared/ReactSymbols';
1414

1515
import {enableEventAPI} from 'shared/ReactFeatureFlags';
1616

17+
type EventTargetChildElement = {
18+
type: string,
19+
props: null | {
20+
style?: {
21+
position?: string,
22+
bottom?: string,
23+
left?: string,
24+
right?: string,
25+
top?: string,
26+
},
27+
},
28+
};
1729
export type Type = string;
1830
export type Props = Object;
1931
export type Container = {|
@@ -170,12 +182,6 @@ export function createInstance(
170182
hostContext: Object,
171183
internalInstanceHandle: Object,
172184
): Instance {
173-
if (__DEV__ && enableEventAPI) {
174-
warning(
175-
hostContext !== EVENT_TOUCH_HIT_TARGET_CONTEXT,
176-
'validateDOMNesting: <TouchHitTarget> must not have any children.',
177-
);
178-
}
179185
return {
180186
type,
181187
props,
@@ -233,10 +239,6 @@ export function createTextInstance(
233239
internalInstanceHandle: Object,
234240
): TextInstance {
235241
if (__DEV__ && enableEventAPI) {
236-
warning(
237-
hostContext !== EVENT_TOUCH_HIT_TARGET_CONTEXT,
238-
'validateDOMNesting: <TouchHitTarget> must not have any children.',
239-
);
240242
warning(
241243
hostContext !== EVENT_COMPONENT_CONTEXT,
242244
'validateDOMNesting: React event components cannot have text DOM nodes as children. ' +
@@ -329,17 +331,62 @@ export function handleEventComponent(
329331
eventResponder: ReactEventResponder,
330332
rootContainerInstance: Container,
331333
internalInstanceHandle: Object,
332-
) {
333-
// TODO: add handleEventComponent implementation
334+
): void {
335+
// noop
336+
}
337+
338+
export function getEventTargetChildElement(
339+
type: Symbol | number,
340+
props: Props,
341+
): null | EventTargetChildElement {
342+
if (enableEventAPI) {
343+
if (type === REACT_EVENT_TARGET_TOUCH_HIT) {
344+
const {bottom, left, right, top} = props;
345+
346+
if (!bottom && !left && !right && !top) {
347+
return null;
348+
}
349+
return {
350+
type: 'div',
351+
props: {
352+
style: {
353+
position: 'absolute',
354+
zIndex: -1,
355+
bottom: bottom ? `-${bottom}px` : '0px',
356+
left: left ? `-${left}px` : '0px',
357+
right: right ? `-${right}px` : '0px',
358+
top: top ? `-${top}px` : '0px',
359+
},
360+
},
361+
};
362+
}
363+
}
364+
return null;
334365
}
335366

336367
export function handleEventTarget(
337368
type: Symbol | number,
338369
props: Props,
339-
parentInstance: Container,
370+
rootContainerInstance: Container,
340371
internalInstanceHandle: Object,
341-
) {
342-
if (type === REACT_EVENT_TARGET_TOUCH_HIT) {
343-
// TODO
372+
): boolean {
373+
if (enableEventAPI) {
374+
if (type === REACT_EVENT_TARGET_TOUCH_HIT) {
375+
// In DEV we do a computed style check on the position to ensure
376+
// the parent host component is correctly position in the document.
377+
if (__DEV__) {
378+
return true;
379+
}
380+
}
344381
}
382+
return false;
383+
}
384+
385+
export function commitEventTarget(
386+
type: Symbol | number,
387+
props: Props,
388+
instance: Instance,
389+
parentInstance: Instance,
390+
): void {
391+
// noop
345392
}

0 commit comments

Comments
 (0)