@@ -45,12 +45,7 @@ import dangerousStyleValue from '../shared/dangerousStyleValue';
4545
4646import type { DOMContainer } from './ReactDOM' ;
4747import 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
5550export type Type = string ;
5651export type Props = {
@@ -75,6 +70,7 @@ type HostContextDev = {
7570 eventData : null | { |
7671 isEventComponent ? : boolean ,
7772 isEventTarget ?: boolean ,
73+ eventTargetType ?: null | Symbol | number ,
7874 | } ,
7975} ;
8076type 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(
874902export 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