Skip to content

Commit 4f72040

Browse files
committed
Borrowed the RNTest PointerEvents example by @hsource
1 parent 735caf3 commit 4f72040

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

packages/rn-tester/js/examples/PointerEvents/PointerEventsExample.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ const React = require('react');
1414

1515
const {StyleSheet, Text, View} = require('react-native');
1616

17+
type ExampleBoxComponentProps = $ReadOnly<{|
18+
onLog: (msg: string) => void,
19+
|}>;
20+
21+
type ExampleBoxProps = $ReadOnly<{|
22+
Component: React.ComponentType<ExampleBoxComponentProps>,
23+
|}>;
24+
25+
type ExampleBoxState = $ReadOnly<{|
26+
log: string[],
27+
|}>;
28+
1729
class ExampleBox extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
1830
state = {
1931
log: [],
@@ -165,6 +177,57 @@ class BoxOnlyExample extends React.Component<$FlowFixMeProps> {
165177
}
166178
}
167179

180+
type OverflowExampleProps = $ReadOnly<{|
181+
overflow: 'hidden' | 'visible',
182+
onLog: (msg: string) => void,
183+
|}>;
184+
185+
class OverflowExample extends React.Component<OverflowExampleProps> {
186+
render() {
187+
const {overflow} = this.props;
188+
return (
189+
<View
190+
onTouchStart={() => this.props.onLog(`A overflow ${overflow} touched`)}
191+
style={[
192+
styles.box,
193+
styles.boxWithOverflowSet,
194+
{overflow: this.props.overflow},
195+
]}>
196+
<DemoText style={styles.text}>A: overflow: {overflow}</DemoText>
197+
<View
198+
onTouchStart={() => this.props.onLog('B overflowing touched')}
199+
style={[styles.box, styles.boxOverflowing]}>
200+
<DemoText style={styles.text}>B: overflowing</DemoText>
201+
</View>
202+
<View
203+
onTouchStart={() => this.props.onLog('C fully outside touched')}
204+
style={[styles.box, styles.boxFullyOutside]}>
205+
<DemoText style={styles.text}>C: fully outside</DemoText>
206+
<View
207+
onTouchStart={() =>
208+
this.props.onLog('D fully outside child touched')
209+
}
210+
style={[styles.box, styles.boxFullyOutsideChild]}>
211+
<DemoText style={styles.text}>D: child of fully outside</DemoText>
212+
</View>
213+
</View>
214+
</View>
215+
);
216+
}
217+
}
218+
219+
class OverflowVisibleExample extends React.Component<ExampleBoxComponentProps> {
220+
render() {
221+
return <OverflowExample {...this.props} overflow="visible" />;
222+
}
223+
}
224+
225+
class OverflowHiddenExample extends React.Component<ExampleBoxComponentProps> {
226+
render() {
227+
return <OverflowExample {...this.props} overflow="hidden" />;
228+
}
229+
}
230+
168231
type ExampleClass = {
169232
Component: React.ComponentType<any>,
170233
title: string,
@@ -191,6 +254,18 @@ const exampleClasses: Array<ExampleClass> = [
191254
description:
192255
"`box-only` causes touch events on the container's child components to pass through and will only detect touch events on the container itself.",
193256
},
257+
{
258+
Component: OverflowVisibleExample,
259+
title: '`overflow: visible`',
260+
description:
261+
'`overflow: visible` style should allow subelements that are outside of the parent box to be touchable. Tapping the parts of Box B outside Box A should print "B touched" and "A touched", and tapping Box C should also print "C touched" and "A touched".',
262+
},
263+
{
264+
Component: OverflowHiddenExample,
265+
title: '`overflow: hidden`',
266+
description:
267+
'`overflow: hidden` style should only allow subelements within the parent box to be touchable. Tapping just below Box A (where Box B would otherwise extend if it weren\'t cut off) should not trigger any touches or messages. Touching Box D (inside the bounds) should print "D touched" and "A touched".',
268+
},
194269
];
195270

196271
const infoToExample = info => {
@@ -221,6 +296,26 @@ const styles = StyleSheet.create({
221296
boxPassedThrough: {
222297
borderColor: '#99bbee',
223298
},
299+
boxWithOverflowSet: {
300+
paddingBottom: 40,
301+
marginBottom: 50,
302+
},
303+
boxOverflowing: {
304+
position: 'absolute',
305+
top: 30,
306+
paddingBottom: 40,
307+
},
308+
boxFullyOutside: {
309+
position: 'absolute',
310+
left: 200,
311+
top: 65,
312+
},
313+
boxFullyOutsideChild: {
314+
position: 'absolute',
315+
left: 0,
316+
top: -65,
317+
width: 100,
318+
},
224319
logText: {
225320
fontSize: 9,
226321
},

0 commit comments

Comments
 (0)