From e3ae85d7c7719a8f1d48bc6f6b555ecadebac265 Mon Sep 17 00:00:00 2001 From: Thomas BARRAS Date: Thu, 27 Sep 2018 16:24:52 -0700 Subject: [PATCH] TVViewPropTypes, PlatformViewPropTypes, DeprecatedTVViewPropTypes (#21372) Summary: Related to #21342 - Split TVViewPropTypes - PlatformViewPropTypes (dependencies) flow types and old prop-type definitions - ViewStylePropTypes (dependencies) rm prop-type Flow tests succeed [GENERAL] [ENHANCEMENT] [TVViewPropTypes.js] - rm prop-types [GENERAL] [ENHANCEMENT] [PlatformViewPropTypes.android.js] - replace prop-types by Flow [GENERAL] [ENHANCEMENT] [PlatformViewPropTypes.ios.js] - replace prop-types by Flow [GENERAL] [ENHANCEMENT] [DeprecatedTVViewPropTypes.js] - old prop-types Pull Request resolved: https://github.com/facebook/react-native/pull/21372 Differential Revision: D10095528 Pulled By: TheSavior fbshipit-source-id: 4fc52ab194f680f95aabefedcbf119d6897672b7 --- .../Components/AppleTV/TVViewPropTypes.js | 73 +++++++++++-------- .../View/PlatformViewPropTypes.android.js | 14 ++++ .../View/PlatformViewPropTypes.ios.js | 16 ++++ .../Components/View/PlatformViewPropTypes.js | 21 ------ .../DeprecatedTVViewPropTypes.js | 25 +++++++ 5 files changed, 96 insertions(+), 53 deletions(-) create mode 100644 Libraries/Components/View/PlatformViewPropTypes.android.js create mode 100644 Libraries/Components/View/PlatformViewPropTypes.ios.js delete mode 100644 Libraries/Components/View/PlatformViewPropTypes.js create mode 100644 Libraries/DeprecatedPropTypes/DeprecatedTVViewPropTypes.js diff --git a/Libraries/Components/AppleTV/TVViewPropTypes.js b/Libraries/Components/AppleTV/TVViewPropTypes.js index 764dfbb8a..ce3651d5f 100644 --- a/Libraries/Components/AppleTV/TVViewPropTypes.js +++ b/Libraries/Components/AppleTV/TVViewPropTypes.js @@ -9,76 +9,85 @@ */ 'use strict'; -const PropTypes = require('prop-types'); + +type TVParallaxPropertiesType = $ReadOnly<{| + /** + * If true, parallax effects are enabled. Defaults to true. + */ + enabled: boolean, + + /** + * Defaults to 2.0. + */ + shiftDistanceX: number, + + /** + * Defaults to 2.0. + */ + shiftDistanceY: number, + + /** + * Defaults to 0.05. + */ + tiltAngle: number, + + /** + * Defaults to 1.0 + */ + magnification: number, +|}>; /** * Additional View properties for Apple TV */ -const TVViewPropTypes = { +export type TVViewProps = $ReadOnly<{| /** - * When set to true, this view will be focusable - * and navigable using the TV remote. + * *(Apple TV only)* When set to true, this view will be focusable + * and navigable using the Apple TV remote. + * + * @platform ios */ - isTVSelectable: PropTypes.bool, + isTVSelectable?: boolean, /** - * May be set to true to force the TV focus engine to move focus to this view. + * *(Apple TV only)* May be set to true to force the Apple TV focus engine to move focus to this view. + * + * @platform ios */ - hasTVPreferredFocus: PropTypes.bool, + hasTVPreferredFocus?: boolean, /** * *(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 */ - tvParallaxProperties: PropTypes.object, + tvParallaxProperties?: TVParallaxPropertiesType, /** * *(Apple TV only)* May be used to change the appearance of the Apple TV parallax effect when this view goes in or out of focus. Defaults to 2.0. * * @platform ios */ - tvParallaxShiftDistanceX: PropTypes.number, + tvParallaxShiftDistanceX?: number, /** * *(Apple TV only)* May be used to change the appearance of the Apple TV parallax effect when this view goes in or out of focus. Defaults to 2.0. * * @platform ios */ - tvParallaxShiftDistanceY: PropTypes.number, + tvParallaxShiftDistanceY?: number, /** * *(Apple TV only)* May be used to change the appearance of the Apple TV parallax effect when this view goes in or out of focus. Defaults to 0.05. * * @platform ios */ - tvParallaxTiltAngle: PropTypes.number, + tvParallaxTiltAngle?: number, /** * *(Apple TV only)* May be used to change the appearance of the Apple TV parallax effect when this view goes in or out of focus. Defaults to 1.0. * * @platform ios */ - tvParallaxMagnification: PropTypes.number, -}; - -export type TVViewProps = $ReadOnly<{| - isTVSelectable?: boolean, - hasTVPreferredFocus?: boolean, - tvParallaxProperties?: Object, - tvParallaxShiftDistanceX?: number, - tvParallaxShiftDistanceY?: number, - tvParallaxTiltAngle?: number, tvParallaxMagnification?: number, |}>; - -module.exports = TVViewPropTypes; diff --git a/Libraries/Components/View/PlatformViewPropTypes.android.js b/Libraries/Components/View/PlatformViewPropTypes.android.js new file mode 100644 index 000000000..f96fe3a62 --- /dev/null +++ b/Libraries/Components/View/PlatformViewPropTypes.android.js @@ -0,0 +1,14 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule PlatformViewPropTypes + * @format + * @flow + */ + +'use strict'; + +export type PlatformViewPropTypes = {}; diff --git a/Libraries/Components/View/PlatformViewPropTypes.ios.js b/Libraries/Components/View/PlatformViewPropTypes.ios.js new file mode 100644 index 000000000..fc8427506 --- /dev/null +++ b/Libraries/Components/View/PlatformViewPropTypes.ios.js @@ -0,0 +1,16 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @providesModule PlatformViewPropTypes + * @format + * @flow + */ + +'use strict'; + +import type {TVViewProps} from 'TVViewPropTypes'; + +export type PlatformViewPropTypes = TVViewProps; diff --git a/Libraries/Components/View/PlatformViewPropTypes.js b/Libraries/Components/View/PlatformViewPropTypes.js deleted file mode 100644 index 282465fdc..000000000 --- a/Libraries/Components/View/PlatformViewPropTypes.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict-local - */ - -const Platform = require('Platform'); - -let TVViewPropTypes = {}; -// We need to always include TVViewPropTypes on Android -// as unlike on iOS we can't detect TV devices at build time -// and hence make view manager export a different list of native properties. -if (Platform.isTV || Platform.OS === 'android') { - TVViewPropTypes = require('TVViewPropTypes'); -} - -module.exports = TVViewPropTypes; diff --git a/Libraries/DeprecatedPropTypes/DeprecatedTVViewPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedTVViewPropTypes.js new file mode 100644 index 000000000..90af60cc2 --- /dev/null +++ b/Libraries/DeprecatedPropTypes/DeprecatedTVViewPropTypes.js @@ -0,0 +1,25 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +const PropTypes = require('prop-types'); + +const DeprecatedTVViewPropTypes = { + isTVSelectable: PropTypes.bool, + hasTVPreferredFocus: PropTypes.bool, + tvParallaxProperties: PropTypes.object, + tvParallaxShiftDistanceX: PropTypes.number, + tvParallaxShiftDistanceY: PropTypes.number, + tvParallaxTiltAngle: PropTypes.number, + tvParallaxMagnification: PropTypes.number, +}; + +module.exports = DeprecatedTVViewPropTypes;