forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHitTestExample.js
More file actions
106 lines (100 loc) · 2.62 KB
/
HitTestExample.js
File metadata and controls
106 lines (100 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
*/
'use strict';
import React from 'react';
import { View, Text, Pressable } from 'react-native';
function HitTestWithOverflowVisibile() {
const [bgColor, setBgColor] = React.useState('red');
return (
<View>
<Text>
Clicking the pressable should work even if it is outside the bounds
of its parent.
</Text>
<View
accessible={true}
accessibilityValue={{ text: bgColor }}
style={{ width: 150, height: 150 }}
testID="visible-overflow-element">
<View
style={{
width: 50,
height: 50,
backgroundColor: 'yellow',
overflow: 'visible',
}}>
<Pressable
style={{
width: 100,
height: 100,
backgroundColor: bgColor,
}}
onPress={() => {
setBgColor(bgColor === 'red' ? 'green' : 'red');
}}>
<Text>Press me</Text>
</Pressable>
</View>
</View>
</View>
);
}
function HitTestWithOverflowHidden() {
const [bgColor, setBgColor] = React.useState('red');
return (
<View>
<Text>
Clicking within the visible view will trigger the pressable.
Clicking outside the bounds, where the pressable extends but is
clipped by its parent overflow:hidden, should not trigger the
pressable.
</Text>
<View
accessible={true}
accessibilityValue={{ text: bgColor }}
style={{ width: 150, height: 150 }}
testID="hidden-overflow-element">
<View
style={{
width: 50,
height: 50,
backgroundColor: 'yellow',
overflow: 'hidden',
}}>
<Pressable
style={{
width: 100,
height: 100,
backgroundColor: bgColor,
}}
onPress={() => {
setBgColor(bgColor === 'red' ? 'green' : 'red');
}}>
<Text>Press me</Text>
</Pressable>
</View>
</View>
</View>
);
}
exports.displayName = 'HitTestExample';
exports.title = 'Hit Testing';
exports.category = 'Basic';
exports.description = 'Test that overflow hidden affect hit testing';
exports.examples = [
{
title: 'overflow visible affects hit testing\n',
render: function () {
return <HitTestWithOverflowVisibile />;
},
},
{
title: 'overflow hidden affects hit testing\n',
render: function () {
return <HitTestWithOverflowHidden />;
},
},
];