@@ -254,115 +254,108 @@ test('should not fire on non-editable TextInput with nested Text', () => {
254
254
expect ( onChangeTextMock ) . not . toHaveBeenCalled ( ) ;
255
255
} ) ;
256
256
257
- test ( 'should not fire on none pointerEvents View' , ( ) => {
258
- const handlePress = jest . fn ( ) ;
259
-
257
+ test ( 'should not fire inside View with pointerEvents="none"' , ( ) => {
258
+ const onPress = jest . fn ( ) ;
260
259
const screen = render (
261
260
< View pointerEvents = "none" >
262
- < Pressable onPress = { handlePress } >
261
+ < Pressable onPress = { onPress } >
263
262
< Text > Trigger</ Text >
264
263
</ Pressable >
265
264
</ View >
266
265
) ;
267
266
268
267
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
269
- expect ( handlePress ) . not . toHaveBeenCalled ( ) ;
268
+ expect ( onPress ) . not . toHaveBeenCalled ( ) ;
270
269
} ) ;
271
270
272
- test ( 'should not fire on box-only pointerEvents View' , ( ) => {
273
- const handlePress = jest . fn ( ) ;
274
-
271
+ test ( 'should not fire inside View with pointerEvents="box-only"' , ( ) => {
272
+ const onPress = jest . fn ( ) ;
275
273
const screen = render (
276
274
< View pointerEvents = "box-only" >
277
- < Pressable onPress = { handlePress } >
275
+ < Pressable onPress = { onPress } >
278
276
< Text > Trigger</ Text >
279
277
</ Pressable >
280
278
</ View >
281
279
) ;
282
280
283
281
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
284
- expect ( handlePress ) . not . toHaveBeenCalled ( ) ;
282
+ expect ( onPress ) . not . toHaveBeenCalled ( ) ;
285
283
} ) ;
286
284
287
- test ( 'should fire on box-none pointerEvents View' , ( ) => {
288
- const handlePress = jest . fn ( ) ;
289
-
285
+ test ( 'should fire inside View with pointerEvents="box-none"' , ( ) => {
286
+ const onPress = jest . fn ( ) ;
290
287
const screen = render (
291
288
< View pointerEvents = "box-none" >
292
- < Pressable onPress = { handlePress } >
289
+ < Pressable onPress = { onPress } >
293
290
< Text > Trigger</ Text >
294
291
</ Pressable >
295
292
</ View >
296
293
) ;
297
294
298
295
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
299
- expect ( handlePress ) . toHaveBeenCalled ( ) ;
296
+ expect ( onPress ) . toHaveBeenCalled ( ) ;
300
297
} ) ;
301
298
302
- test ( 'should fire on auto pointerEvents View' , ( ) => {
303
- const handlePress = jest . fn ( ) ;
304
-
299
+ test ( 'should fire inside View with pointerEvents="auto"' , ( ) => {
300
+ const onPress = jest . fn ( ) ;
305
301
const screen = render (
306
302
< View pointerEvents = "auto" >
307
- < Pressable onPress = { handlePress } >
303
+ < Pressable onPress = { onPress } >
308
304
< Text > Trigger</ Text >
309
305
</ Pressable >
310
306
</ View >
311
307
) ;
312
308
313
309
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
314
- expect ( handlePress ) . toHaveBeenCalled ( ) ;
310
+ expect ( onPress ) . toHaveBeenCalled ( ) ;
315
311
} ) ;
316
312
317
- test ( 'should not fire on box-only pointerEvents View with nested elements' , ( ) => {
318
- const handlePress = jest . fn ( ) ;
319
-
313
+ test ( 'should not fire deeply inside View with pointerEvents="box-only"' , ( ) => {
314
+ const onPress = jest . fn ( ) ;
320
315
const screen = render (
321
316
< View pointerEvents = "box-only" >
322
317
< View >
323
- < Pressable onPress = { handlePress } >
318
+ < Pressable onPress = { onPress } >
324
319
< Text > Trigger</ Text >
325
320
</ Pressable >
326
321
</ View >
327
322
</ View >
328
323
) ;
329
324
330
325
fireEvent . press ( screen . getByText ( 'Trigger' ) ) ;
331
- expect ( handlePress ) . not . toHaveBeenCalled ( ) ;
326
+ expect ( onPress ) . not . toHaveBeenCalled ( ) ;
332
327
} ) ;
333
328
334
- test ( 'should fire non-pointer events on box-none pointerEvents View' , ( ) => {
335
- const handleTouchStart = jest . fn ( ) ;
336
-
329
+ test ( 'should fire non-pointer events inside View with pointerEvents="box-none"' , ( ) => {
330
+ const onTouchStart = jest . fn ( ) ;
337
331
const screen = render (
338
- < View
339
- pointerEvents = "box-none"
340
- onTouchStart = { handleTouchStart }
341
- testID = "touch-start-view"
342
- >
343
- < Pressable onPress = { ( ) => { } } >
344
- < Text > Trigger</ Text >
345
- </ Pressable >
346
- </ View >
332
+ < View testID = "view" pointerEvents = "box-none" onTouchStart = { onTouchStart } />
347
333
) ;
348
334
349
- fireEvent ( screen . getByTestId ( 'touch-start- view' ) , 'touchStart' ) ;
350
- expect ( handleTouchStart ) . toHaveBeenCalled ( ) ;
335
+ fireEvent ( screen . getByTestId ( 'view' ) , 'touchStart' ) ;
336
+ expect ( onTouchStart ) . toHaveBeenCalled ( ) ;
351
337
} ) ;
352
338
353
- test ( 'should fire non-touch events on box-none pointerEvents View' , ( ) => {
354
- const handleLayout = jest . fn ( ) ;
339
+ test ( 'should fire non-touch events inside View with pointerEvents="box-none"' , ( ) => {
340
+ const onLayout = jest . fn ( ) ;
341
+ const screen = render (
342
+ < View testID = "view" pointerEvents = "box-none" onLayout = { onLayout } />
343
+ ) ;
344
+
345
+ fireEvent ( screen . getByTestId ( 'view' ) , 'layout' ) ;
346
+ expect ( onLayout ) . toHaveBeenCalled ( ) ;
347
+ } ) ;
355
348
349
+ // This test if pointerEvents="box-only" on composite `Pressable` is blocking
350
+ // the 'press' event on host View rendered by pressable.
351
+ test ( 'should fire on Pressable with pointerEvents="box-only' , ( ) => {
352
+ const onPress = jest . fn ( ) ;
356
353
const screen = render (
357
- < View pointerEvents = "box-none" onLayout = { handleLayout } testID = "layout-view" >
358
- < Pressable onPress = { ( ) => { } } >
359
- < Text > Trigger</ Text >
360
- </ Pressable >
361
- </ View >
354
+ < Pressable testID = "pressable" pointerEvents = "box-only" onPress = { onPress } />
362
355
) ;
363
356
364
- fireEvent ( screen . getByTestId ( 'layout-view' ) , 'layout' ) ;
365
- expect ( handleLayout ) . toHaveBeenCalled ( ) ;
357
+ fireEvent . press ( screen . getByTestId ( 'pressable' ) ) ;
358
+ expect ( onPress ) . toHaveBeenCalled ( ) ;
366
359
} ) ;
367
360
368
361
test ( 'should pass event up on disabled TouchableOpacity' , ( ) => {
0 commit comments