2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-03-23 22:07:33 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {StyleSheet, Text, View} = ReactNative;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ExampleBox extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
log: [],
|
|
|
|
};
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
handleLog = msg => {
|
2015-01-30 01:10:49 +00:00
|
|
|
this.state.log = this.state.log.concat([msg]);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
flushReactChanges = () => {
|
2015-01-30 01:10:49 +00:00
|
|
|
this.forceUpdate();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
/**
|
|
|
|
* Capture phase of bubbling to append separator before any of the bubbling
|
|
|
|
* happens.
|
|
|
|
*/
|
2016-07-26 08:00:02 +00:00
|
|
|
handleTouchCapture = () => {
|
2015-01-30 01:10:49 +00:00
|
|
|
this.state.log = this.state.log.concat(['---']);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View
|
|
|
|
onTouchEndCapture={this.handleTouchCapture}
|
|
|
|
onTouchStart={this.flushReactChanges}>
|
2017-08-29 21:54:33 +00:00
|
|
|
{/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
|
|
|
|
* comment suppresses an error when upgrading Flow's support for
|
|
|
|
* React. To see the error delete this comment and run Flow. */}
|
2015-01-30 01:10:49 +00:00
|
|
|
<this.props.Component onLog={this.handleLog} />
|
|
|
|
</View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<View style={styles.logBox}>
|
2015-01-30 01:10:49 +00:00
|
|
|
<DemoText style={styles.logText}>
|
|
|
|
{this.state.log.join('\n')}
|
|
|
|
</DemoText>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class NoneExample extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
|
|
style={styles.box}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
<View
|
2015-03-05 05:06:49 +00:00
|
|
|
pointerEvents="none"
|
2015-01-30 01:10:49 +00:00
|
|
|
onTouchStart={() => this.props.onLog('B none touched')}
|
|
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
|
|
B: none
|
|
|
|
</DemoText>
|
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
|
|
C: unspecified
|
|
|
|
</DemoText>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Special demo text that makes itself untouchable so that it doesn't destroy
|
|
|
|
* the experiment and confuse the output.
|
|
|
|
*/
|
2017-08-18 01:36:54 +00:00
|
|
|
class DemoText extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
2015-03-05 05:06:49 +00:00
|
|
|
<View pointerEvents="none">
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={this.props.style}>{this.props.children}</Text>
|
2015-01-30 01:10:49 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class BoxNoneExample extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
|
|
style={styles.box}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
<View
|
2015-03-05 05:06:49 +00:00
|
|
|
pointerEvents="box-none"
|
|
|
|
onTouchStart={() => this.props.onLog('B box-none touched')}
|
2015-01-30 01:10:49 +00:00
|
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
2015-03-05 05:06:49 +00:00
|
|
|
B: box-none
|
2015-01-30 01:10:49 +00:00
|
|
|
</DemoText>
|
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
|
|
style={styles.box}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={styles.text}>C: unspecified</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
</View>
|
|
|
|
<View
|
2015-03-05 05:06:49 +00:00
|
|
|
pointerEvents="auto"
|
2018-05-11 20:32:37 +00:00
|
|
|
onTouchStart={() =>
|
|
|
|
this.props.onLog('C explicitly unspecified touched')
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
style={[styles.box]}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={[styles.text]}>C: explicitly unspecified</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class BoxOnlyExample extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('A unspecified touched')}
|
|
|
|
style={styles.box}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={styles.text}>A: unspecified</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
<View
|
2015-03-05 05:06:49 +00:00
|
|
|
pointerEvents="box-only"
|
|
|
|
onTouchStart={() => this.props.onLog('B box-only touched')}
|
2015-01-30 01:10:49 +00:00
|
|
|
style={styles.box}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<DemoText style={styles.text}>B: box-only</DemoText>
|
2015-01-30 01:10:49 +00:00
|
|
|
<View
|
|
|
|
onTouchStart={() => this.props.onLog('C unspecified touched')}
|
|
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
|
|
C: unspecified
|
|
|
|
</DemoText>
|
|
|
|
</View>
|
|
|
|
<View
|
2015-03-05 05:06:49 +00:00
|
|
|
pointerEvents="auto"
|
2018-05-11 20:32:37 +00:00
|
|
|
onTouchStart={() =>
|
|
|
|
this.props.onLog('C explicitly unspecified touched')
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
style={[styles.box, styles.boxPassedThrough]}>
|
|
|
|
<DemoText style={[styles.text, styles.textPassedThrough]}>
|
|
|
|
C: explicitly unspecified
|
|
|
|
</DemoText>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
type ExampleClass = {
|
2017-08-18 01:36:54 +00:00
|
|
|
Component: React.ComponentType<any>,
|
2015-05-12 21:22:22 +00:00
|
|
|
title: string,
|
|
|
|
description: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
var exampleClasses: Array<ExampleClass> = [
|
2015-01-30 01:10:49 +00:00
|
|
|
{
|
|
|
|
Component: NoneExample,
|
|
|
|
title: '`none`',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
'`none` causes touch events on the container and its child components to pass through to the parent container.',
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Component: BoxNoneExample,
|
2015-03-05 05:06:49 +00:00
|
|
|
title: '`box-none`',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
'`box-none` causes touch events on the container to pass through and will only detect touch events on its child components.',
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Component: BoxOnlyExample,
|
2015-03-05 05:06:49 +00:00
|
|
|
title: '`box-only`',
|
2018-05-11 20:32:37 +00:00
|
|
|
description:
|
|
|
|
"`box-only` causes touch events on the container's child components to pass through and will only detect touch events on the container itself.",
|
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
];
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
var infoToExample = info => {
|
2015-01-30 01:10:49 +00:00
|
|
|
return {
|
|
|
|
title: info.title,
|
|
|
|
description: info.description,
|
|
|
|
render: function() {
|
|
|
|
return <ExampleBox key={info.title} Component={info.Component} />;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
text: {
|
|
|
|
fontSize: 10,
|
|
|
|
color: '#5577cc',
|
|
|
|
},
|
|
|
|
textPassedThrough: {
|
|
|
|
color: '#88aadd',
|
|
|
|
},
|
|
|
|
box: {
|
|
|
|
backgroundColor: '#aaccff',
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: '#7799cc',
|
|
|
|
padding: 10,
|
|
|
|
margin: 5,
|
|
|
|
},
|
|
|
|
boxPassedThrough: {
|
|
|
|
borderColor: '#99bbee',
|
|
|
|
},
|
|
|
|
logText: {
|
|
|
|
fontSize: 9,
|
|
|
|
},
|
|
|
|
logBox: {
|
|
|
|
padding: 20,
|
|
|
|
margin: 10,
|
|
|
|
borderWidth: 0.5,
|
|
|
|
borderColor: '#f0f0f0',
|
|
|
|
backgroundColor: '#f9f9f9',
|
|
|
|
},
|
|
|
|
bottomSpacer: {
|
|
|
|
marginBottom: 100,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = 'Pointer Events';
|
2018-05-11 20:32:37 +00:00
|
|
|
exports.description =
|
|
|
|
'Demonstrates the use of the pointerEvents prop of a ' +
|
2015-09-15 21:46:54 +00:00
|
|
|
'View to control how touches should be handled.';
|
2018-04-17 12:37:02 +00:00
|
|
|
/* $FlowFixMe(>=0.70.0 site=react_native_fb) This comment suppresses an error
|
|
|
|
* found when Flow v0.70 was deployed. To see the error delete this comment
|
|
|
|
* and run Flow. */
|
2015-01-30 01:10:49 +00:00
|
|
|
exports.examples = exampleClasses.map(infoToExample);
|