Skip to content

Commit 39f051a

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Add a test case ensuring touch events are dispatched to views overflowing ScrollView content container (facebook#49967)
Summary: Pull Request resolved: facebook#49967 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D71030561 fbshipit-source-id: 4d73a0c4d3dc22b83c47091ba8de1d5261ab9ed5
1 parent e70961e commit 39f051a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

packages/rn-tester/js/examples/ScrollView/ScrollViewExample.js

+60
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ const examples: Array<RNTesterModuleExample> = [
457457
return <ClippingExampleHorizontal />;
458458
},
459459
},
460+
{
461+
name: 'touchableChildrenOverflowingContainerHorizontal',
462+
title:
463+
'<ScrollView> touchable children overflow content container (horizontal = true)\n',
464+
description:
465+
"Children that overflow ScrollView's content container should still receive touch events",
466+
render() {
467+
return <ChildrenWithTouchEventsOverflowingContainerHorizontal />;
468+
},
469+
},
460470
];
461471

462472
if (Platform.OS === 'ios') {
@@ -1352,6 +1362,56 @@ function ClippingExampleHorizontal() {
13521362
);
13531363
}
13541364

1365+
function TouchableItem({index}: {index: number}) {
1366+
const [pressed, setPressed] = useState(false);
1367+
1368+
return (
1369+
<View
1370+
onTouchStart={() => setPressed(p => !p)}
1371+
testID={`touchable_item_${index}`}
1372+
style={{
1373+
position: 'relative',
1374+
flexDirection: 'row',
1375+
justifyContent: 'center',
1376+
alignItems: 'center',
1377+
flexGrow: 1,
1378+
flexShrink: 1,
1379+
flexBasis: '25%',
1380+
margin: 5,
1381+
backgroundColor: pressed ? 'gray' : 'lightgray',
1382+
}}>
1383+
<Text>Item {index}</Text>
1384+
</View>
1385+
);
1386+
}
1387+
1388+
function ChildrenWithTouchEventsOverflowingContainerHorizontal() {
1389+
return (
1390+
<ScrollView
1391+
testID="touchable_overflowing_container_horizontal"
1392+
horizontal={true}
1393+
style={[styles.scrollView, {height: 200, width: '100%'}]}
1394+
contentContainerStyle={{
1395+
backgroundColor: 'red',
1396+
}}
1397+
nestedScrollEnabled={true}>
1398+
<View
1399+
style={{
1400+
display: 'flex',
1401+
flexDirection: 'row',
1402+
justifyContent: 'flex-start',
1403+
alignItems: 'stretch',
1404+
minHeight: 45,
1405+
minWidth: '100%',
1406+
}}>
1407+
<TouchableItem index={1} />
1408+
<TouchableItem index={2} />
1409+
<TouchableItem index={3} />
1410+
</View>
1411+
</ScrollView>
1412+
);
1413+
}
1414+
13551415
class Item extends React.PureComponent<{
13561416
msg?: string,
13571417
style?: ViewStyleProp,

0 commit comments

Comments
 (0)