Skip to content

Commit

Permalink
Flow type TouchableHighlight
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7983631

fbshipit-source-id: 98b3708b26e2bf96426d5acaa5c7e2311a3a34f6
  • Loading branch information
elicwhite authored and facebook-github-bot committed May 13, 2018
1 parent 6b3aad3 commit f0c18dc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
24 changes: 22 additions & 2 deletions Libraries/Components/Touchable/TouchableHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const createReactClass = require('create-react-class');
const ensurePositiveDelayProps = require('ensurePositiveDelayProps');

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 = {
activeOpacity: 0.85,
Expand All @@ -34,6 +37,23 @@ const DEFAULT_PROPS = {

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.
* On press down, the opacity of the wrapped view is decreased, which allows
Expand Down Expand Up @@ -131,7 +151,7 @@ const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
*
*/

const TouchableHighlight = createReactClass({
const TouchableHighlight = ((createReactClass({
displayName: 'TouchableHighlight',
propTypes: {
...TouchableWithoutFeedback.propTypes,
Expand Down Expand Up @@ -362,6 +382,6 @@ const TouchableHighlight = createReactClass({
</View>
);
},
});
}): any): React.ComponentType<Props>);

module.exports = TouchableHighlight;
16 changes: 5 additions & 11 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@
const EdgeInsetsPropType = require('EdgeInsetsPropType');
const React = require('React');
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 Touchable = require('Touchable');

const createReactClass = require('create-react-class');
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 {
Expand All @@ -35,21 +29,21 @@ import type {PressEvent} from 'CoreEventTypes';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type {
AccessibilityComponentType,
AccessibilityTrait,
AccessibilityTraits as AccessibilityTraitsFlow,
} from 'ViewAccessibility';

const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};

type Props = $ReadOnly<{|
accessible?: boolean,
accessibilityComponentType?: AccessibilityComponentType,
export type Props = $ReadOnly<{|
accessible?: ?boolean,
accessibilityComponentType?: ?AccessibilityComponentType,
accessibilityLabel?:
| null
| React$PropType$Primitive<any>
| string
| Array<any>
| any,
accessibilityTraits?: AccessibilityTrait | Array<AccessibilityTrait>,
accessibilityTraits?: ?AccessibilityTraitsFlow,
children?: ?React.Node,
delayLongPress?: ?number,
delayPressIn?: ?number,
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/View/ViewAccessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export type AccessibilityTrait =
| 'allowsDirectInteraction'
| 'pageTurn';

export type AccessibilityTraits =
| AccessibilityTrait
| $ReadOnlyArray<AccessibilityTrait>;

export type AccessibilityComponentType =
| 'none'
| 'button'
Expand Down
5 changes: 4 additions & 1 deletion RNTester/js/RNTesterExampleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class RowComponent extends React.PureComponent<{
render() {
const {item} = this.props;
return (
<TouchableHighlight {...this.props} onPress={this._onPress}>
<TouchableHighlight
onShowUnderlay={this.props.onShowUnderlay}
onHideUnderlay={this.props.onHideUnderlay}
onPress={this._onPress}>
<View style={styles.row}>
<Text style={styles.rowTitleText}>{item.module.title}</Text>
<Text style={styles.rowDetailText}>{item.module.description}</Text>
Expand Down
3 changes: 0 additions & 3 deletions RNTester/js/TouchableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ exports.examples = [
<TouchableHighlight
style={styles.wrapper}
activeOpacity={1}
animationVelocity={0}
tvParallaxProperties={{
pressMagnification: 1.3,
pressDuration: 0.6,
Expand Down Expand Up @@ -348,7 +347,6 @@ class TouchableDisabled extends React.Component<{}> {
<TouchableHighlight
activeOpacity={1}
disabled={true}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}>
Expand All @@ -357,7 +355,6 @@ class TouchableDisabled extends React.Component<{}> {

<TouchableHighlight
activeOpacity={1}
animationVelocity={0}
underlayColor="rgb(210, 230, 255)"
style={[styles.row, styles.block]}
onPress={() => console.log('custom THW text - highlight')}>
Expand Down

0 comments on commit f0c18dc

Please sign in to comment.