Flow type TouchableHighlight

Reviewed By: yungsters

Differential Revision: D7983631

fbshipit-source-id: 98b3708b26e2bf96426d5acaa5c7e2311a3a34f6
This commit is contained in:
Eli White 2018-05-12 23:10:46 -07:00 committed by Facebook Github Bot
parent 6b3aad31f6
commit f0c18dc820
5 changed files with 35 additions and 17 deletions

View File

@ -25,6 +25,9 @@ const createReactClass = require('create-react-class');
const ensurePositiveDelayProps = require('ensurePositiveDelayProps'); const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
import type {PressEvent} from 'CoreEventTypes'; import type {PressEvent} from 'CoreEventTypes';
import type {Props as TouchableWithoutFeedbackProps} from 'TouchableWithoutFeedback';
import type {ViewStyleProp} from 'StyleSheet';
import type {ColorValue} from 'StyleSheetTypes';
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
activeOpacity: 0.85, activeOpacity: 0.85,
@ -34,6 +37,23 @@ const DEFAULT_PROPS = {
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
type IOSProps = $ReadOnly<{|
hasTVPreferredFocus?: ?boolean,
tvParallaxProperties?: ?Object,
|}>;
type Props = $ReadOnly<{|
...TouchableWithoutFeedbackProps,
...IOSProps,
activeOpacity?: ?number,
underlayColor?: ?ColorValue,
style?: ?ViewStyleProp,
onShowUnderlay?: ?Function,
onHideUnderlay?: ?Function,
testOnly_pressed?: ?boolean,
|}>;
/** /**
* A wrapper for making views respond properly to touches. * A wrapper for making views respond properly to touches.
* On press down, the opacity of the wrapped view is decreased, which allows * On press down, the opacity of the wrapped view is decreased, which allows
@ -131,7 +151,7 @@ const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
* *
*/ */
const TouchableHighlight = createReactClass({ const TouchableHighlight = ((createReactClass({
displayName: 'TouchableHighlight', displayName: 'TouchableHighlight',
propTypes: { propTypes: {
...TouchableWithoutFeedback.propTypes, ...TouchableWithoutFeedback.propTypes,
@ -362,6 +382,6 @@ const TouchableHighlight = createReactClass({
</View> </View>
); );
}, },
}); }): any): React.ComponentType<Props>);
module.exports = TouchableHighlight; module.exports = TouchableHighlight;

View File

@ -13,17 +13,11 @@
const EdgeInsetsPropType = require('EdgeInsetsPropType'); const EdgeInsetsPropType = require('EdgeInsetsPropType');
const React = require('React'); const React = require('React');
const PropTypes = require('prop-types'); const PropTypes = require('prop-types');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const TimerMixin = require('react-timer-mixin'); const TimerMixin = require('react-timer-mixin');
const Touchable = require('Touchable'); const Touchable = require('Touchable');
const createReactClass = require('create-react-class'); const createReactClass = require('create-react-class');
const ensurePositiveDelayProps = require('ensurePositiveDelayProps'); const ensurePositiveDelayProps = require('ensurePositiveDelayProps');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const warning = require('fbjs/lib/warning'); const warning = require('fbjs/lib/warning');
const { const {
@ -35,21 +29,21 @@ import type {PressEvent} from 'CoreEventTypes';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType'; import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type { import type {
AccessibilityComponentType, AccessibilityComponentType,
AccessibilityTrait, AccessibilityTraits as AccessibilityTraitsFlow,
} from 'ViewAccessibility'; } from 'ViewAccessibility';
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
type Props = $ReadOnly<{| export type Props = $ReadOnly<{|
accessible?: boolean, accessible?: ?boolean,
accessibilityComponentType?: AccessibilityComponentType, accessibilityComponentType?: ?AccessibilityComponentType,
accessibilityLabel?: accessibilityLabel?:
| null | null
| React$PropType$Primitive<any> | React$PropType$Primitive<any>
| string | string
| Array<any> | Array<any>
| any, | any,
accessibilityTraits?: AccessibilityTrait | Array<AccessibilityTrait>, accessibilityTraits?: ?AccessibilityTraitsFlow,
children?: ?React.Node, children?: ?React.Node,
delayLongPress?: ?number, delayLongPress?: ?number,
delayPressIn?: ?number, delayPressIn?: ?number,

View File

@ -29,6 +29,10 @@ export type AccessibilityTrait =
| 'allowsDirectInteraction' | 'allowsDirectInteraction'
| 'pageTurn'; | 'pageTurn';
export type AccessibilityTraits =
| AccessibilityTrait
| $ReadOnlyArray<AccessibilityTrait>;
export type AccessibilityComponentType = export type AccessibilityComponentType =
| 'none' | 'none'
| 'button' | 'button'

View File

@ -53,7 +53,10 @@ class RowComponent extends React.PureComponent<{
render() { render() {
const {item} = this.props; const {item} = this.props;
return ( return (
<TouchableHighlight {...this.props} onPress={this._onPress}> <TouchableHighlight
onShowUnderlay={this.props.onShowUnderlay}
onHideUnderlay={this.props.onHideUnderlay}
onPress={this._onPress}>
<View style={styles.row}> <View style={styles.row}>
<Text style={styles.rowTitleText}>{item.module.title}</Text> <Text style={styles.rowTitleText}>{item.module.title}</Text>
<Text style={styles.rowDetailText}>{item.module.description}</Text> <Text style={styles.rowDetailText}>{item.module.description}</Text>

View File

@ -55,7 +55,6 @@ exports.examples = [
<TouchableHighlight <TouchableHighlight
style={styles.wrapper} style={styles.wrapper}
activeOpacity={1} activeOpacity={1}
animationVelocity={0}
tvParallaxProperties={{ tvParallaxProperties={{
pressMagnification: 1.3, pressMagnification: 1.3,
pressDuration: 0.6, pressDuration: 0.6,
@ -348,7 +347,6 @@ class TouchableDisabled extends React.Component<{}> {
<TouchableHighlight <TouchableHighlight
activeOpacity={1} activeOpacity={1}
disabled={true} disabled={true}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)" underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]} style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}> onPress={() => console.log('custom THW text - highlight')}>
@ -357,7 +355,6 @@ class TouchableDisabled extends React.Component<{}> {
<TouchableHighlight <TouchableHighlight
activeOpacity={1} activeOpacity={1}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)" underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]} style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}> onPress={() => console.log('custom THW text - highlight')}>