From a97d104b44daa068fa3848cc6c3225356f9dc318 Mon Sep 17 00:00:00 2001 From: Thomas BARRAS Date: Wed, 21 Nov 2018 14:32:44 -0800 Subject: [PATCH] Flow strict TouchableHighlight (#22173) Summary: Related to #22100 Enhance Flow types for TouchableOpacity specifying underlay functions and TvParallaxPropertiesType. I had to export and enhance TvParallaxPropertiesType from TVViewPropTypes file. This does not break this other PR also using this exported type. #22146 There is still some work to do in order to turn flow to strict mode. - All flow tests succeed. [GENERAL] [ENHANCEMENT] [TouchableHighlight.js] - Flow types [GENERAL] [ENHANCEMENT] [TVViewPropTypes.js] - Export and enhance type Pull Request resolved: https://github.com/facebook/react-native/pull/22173 Differential Revision: D13033441 Pulled By: RSNara fbshipit-source-id: 26a38970923dc7e6c02c03da5d08483a3f1fbd36 --- .../Components/AppleTV/TVViewPropTypes.js | 25 +++++++++++++++---- .../Touchable/TouchableHighlight.js | 20 ++++----------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Libraries/Components/AppleTV/TVViewPropTypes.js b/Libraries/Components/AppleTV/TVViewPropTypes.js index 607034027f08da..d7492967bc128b 100644 --- a/Libraries/Components/AppleTV/TVViewPropTypes.js +++ b/Libraries/Components/AppleTV/TVViewPropTypes.js @@ -14,27 +14,42 @@ export type TVParallaxPropertiesType = $ReadOnly<{| /** * If true, parallax effects are enabled. Defaults to true. */ - enabled: boolean, + enabled?: boolean, /** * Defaults to 2.0. */ - shiftDistanceX: number, + shiftDistanceX?: number, /** * Defaults to 2.0. */ - shiftDistanceY: number, + shiftDistanceY?: number, /** * Defaults to 0.05. */ - tiltAngle: number, + tiltAngle?: number, /** * Defaults to 1.0 */ - magnification: number, + magnification?: number, + + /** + * Defaults to 1.0 + */ + pressMagnification?: number, + + /** + * Defaults to 0.3 + */ + pressDuration?: number, + + /** + * Defaults to 0.3 + */ + pressDelay?: number, |}>; /** diff --git a/Libraries/Components/Touchable/TouchableHighlight.js b/Libraries/Components/Touchable/TouchableHighlight.js index f4e81f37485e10..03e7cd8b8af7ac 100644 --- a/Libraries/Components/Touchable/TouchableHighlight.js +++ b/Libraries/Components/Touchable/TouchableHighlight.js @@ -28,6 +28,7 @@ import type {PressEvent} from 'CoreEventTypes'; import type {ViewStyleProp} from 'StyleSheet'; import type {ColorValue} from 'StyleSheetTypes'; import type {Props as TouchableWithoutFeedbackProps} from 'TouchableWithoutFeedback'; +import type {TVParallaxPropertiesType} from 'TVViewPropTypes'; const DEFAULT_PROPS = { activeOpacity: 0.85, @@ -39,7 +40,7 @@ const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; type IOSProps = $ReadOnly<{| hasTVPreferredFocus?: ?boolean, - tvParallaxProperties?: ?Object, + tvParallaxProperties?: ?TVParallaxPropertiesType, |}>; type Props = $ReadOnly<{| @@ -49,8 +50,8 @@ type Props = $ReadOnly<{| activeOpacity?: ?number, underlayColor?: ?ColorValue, style?: ?ViewStyleProp, - onShowUnderlay?: ?Function, - onHideUnderlay?: ?Function, + onShowUnderlay?: ?() => void, + onHideUnderlay?: ?() => void, testOnly_pressed?: ?boolean, |}>; @@ -185,18 +186,7 @@ const TouchableHighlight = ((createReactClass({ */ hasTVPreferredFocus: PropTypes.bool, /** - * *(Apple TV only)* Object with properties to control Apple TV parallax effects. - * - * enabled: If true, parallax effects are enabled. Defaults to true. - * shiftDistanceX: Defaults to 2.0. - * shiftDistanceY: Defaults to 2.0. - * tiltAngle: Defaults to 0.05. - * magnification: Defaults to 1.0. - * pressMagnification: Defaults to 1.0. - * pressDuration: Defaults to 0.3. - * pressDelay: Defaults to 0.0. - * - * @platform ios + * Apple TV parallax effects */ tvParallaxProperties: PropTypes.object, /**