From f0c18dc820537892dcc33d5aebbf4f52cf299b95 Mon Sep 17 00:00:00 2001 From: Eli White Date: Sat, 12 May 2018 23:10:46 -0700 Subject: [PATCH] Flow type TouchableHighlight Reviewed By: yungsters Differential Revision: D7983631 fbshipit-source-id: 98b3708b26e2bf96426d5acaa5c7e2311a3a34f6 --- .../Touchable/TouchableHighlight.js | 24 +++++++++++++++++-- .../Touchable/TouchableWithoutFeedback.js | 16 ++++--------- .../Components/View/ViewAccessibility.js | 4 ++++ RNTester/js/RNTesterExampleList.js | 5 +++- RNTester/js/TouchableExample.js | 3 --- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Libraries/Components/Touchable/TouchableHighlight.js b/Libraries/Components/Touchable/TouchableHighlight.js index 4d8f63eec..117884faf 100644 --- a/Libraries/Components/Touchable/TouchableHighlight.js +++ b/Libraries/Components/Touchable/TouchableHighlight.js @@ -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, @@ -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 @@ -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, @@ -362,6 +382,6 @@ const TouchableHighlight = createReactClass({ ); }, -}); +}): any): React.ComponentType); module.exports = TouchableHighlight; diff --git a/Libraries/Components/Touchable/TouchableWithoutFeedback.js b/Libraries/Components/Touchable/TouchableWithoutFeedback.js index f80fd9a07..2cd249cb5 100755 --- a/Libraries/Components/Touchable/TouchableWithoutFeedback.js +++ b/Libraries/Components/Touchable/TouchableWithoutFeedback.js @@ -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 { @@ -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 | string | Array | any, - accessibilityTraits?: AccessibilityTrait | Array, + accessibilityTraits?: ?AccessibilityTraitsFlow, children?: ?React.Node, delayLongPress?: ?number, delayPressIn?: ?number, diff --git a/Libraries/Components/View/ViewAccessibility.js b/Libraries/Components/View/ViewAccessibility.js index c5e44e289..b6e46f5b6 100644 --- a/Libraries/Components/View/ViewAccessibility.js +++ b/Libraries/Components/View/ViewAccessibility.js @@ -29,6 +29,10 @@ export type AccessibilityTrait = | 'allowsDirectInteraction' | 'pageTurn'; +export type AccessibilityTraits = + | AccessibilityTrait + | $ReadOnlyArray; + export type AccessibilityComponentType = | 'none' | 'button' diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index d031caef4..c9ccce1a8 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -53,7 +53,10 @@ class RowComponent extends React.PureComponent<{ render() { const {item} = this.props; return ( - + {item.module.title} {item.module.description} diff --git a/RNTester/js/TouchableExample.js b/RNTester/js/TouchableExample.js index 3ce3faa45..711bd8bc1 100644 --- a/RNTester/js/TouchableExample.js +++ b/RNTester/js/TouchableExample.js @@ -55,7 +55,6 @@ exports.examples = [ { console.log('custom THW text - highlight')}> @@ -357,7 +355,6 @@ class TouchableDisabled extends React.Component<{}> { console.log('custom THW text - highlight')}>