From ae40651f9273e187218823b7d57370d180cae039 Mon Sep 17 00:00:00 2001 From: empyrical Date: Mon, 8 Oct 2018 23:25:48 -0600 Subject: [PATCH 1/2] ProgressViewIOS: Remove PropTypes and NativeEventsMixin, convert to functional component --- .../ProgressViewIOS/ProgressViewIOS.ios.js | 95 ++++++++----------- 1 file changed, 40 insertions(+), 55 deletions(-) diff --git a/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js b/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js index 56305508edc23c..1f6056535d619f 100644 --- a/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js +++ b/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js @@ -10,17 +10,13 @@ 'use strict'; -const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes'); -const Image = require('Image'); -const NativeMethodsMixin = require('NativeMethodsMixin'); -const PropTypes = require('prop-types'); const React = require('React'); -const ReactNative = require('ReactNative'); const StyleSheet = require('StyleSheet'); const createReactClass = require('create-react-class'); const requireNativeComponent = require('requireNativeComponent'); +import type {NativeComponent} from 'ReactNative'; import type {ImageSource} from 'ImageSource'; import type {ColorValue} from 'StyleSheetTypes'; import type {ViewProps} from 'ViewPropTypes'; @@ -29,63 +25,51 @@ const RCTProgressView = requireNativeComponent('RCTProgressView'); type Props = $ReadOnly<{| ...ViewProps, + + /** + * The progress bar style. + */ progressViewStyle?: ?('default' | 'bar'), + + /** + * The progress value (between 0 and 1). + */ progress?: ?number, + + /** + * The tint color of the progress bar itself. + */ progressTintColor?: ?ColorValue, - trackTintColor?: ?string, + + /** + * The tint color of the progress bar track. + */ + trackTintColor?: ?ColorValue, + + /** + * A stretchable image to display as the progress bar. + */ progressImage?: ?ImageSource, + + /** + * A stretchable image to display behind the progress bar. + */ trackImage?: ?ImageSource, |}>; /** * Use `ProgressViewIOS` to render a UIProgressView on iOS. */ -const ProgressViewIOS = createReactClass({ - displayName: 'ProgressViewIOS', - mixins: [NativeMethodsMixin], - - propTypes: { - ...DeprecatedViewPropTypes, - /** - * The progress bar style. - */ - progressViewStyle: PropTypes.oneOf(['default', 'bar']), - - /** - * The progress value (between 0 and 1). - */ - progress: PropTypes.number, - - /** - * The tint color of the progress bar itself. - */ - progressTintColor: PropTypes.string, - - /** - * The tint color of the progress bar track. - */ - trackTintColor: PropTypes.string, - - /** - * A stretchable image to display as the progress bar. - */ - progressImage: Image.propTypes.source, - - /** - * A stretchable image to display behind the progress bar. - */ - trackImage: Image.propTypes.source, - }, - - render: function() { - return ( - - ); - }, -}); +const ProgressViewIOS = ( + props: Props, + forwardedRef?: ?React.Ref<'RCTProgressView'>, +) => ( + +); const styles = StyleSheet.create({ progressView: { @@ -93,6 +77,7 @@ const styles = StyleSheet.create({ }, }); -module.exports = ((ProgressViewIOS: any): Class< - ReactNative.NativeComponent, ->); +// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet. +const ProgressViewIOSWithRef = React.forwardRef(ProgressViewIOS); + +module.exports = (ProgressViewIOSWithRef: Class>); From b2836dcc9efe92bb7ff4614dd34df7b8f33847c4 Mon Sep 17 00:00:00 2001 From: empyrical Date: Tue, 9 Oct 2018 00:06:22 -0600 Subject: [PATCH 2/2] Clean up flow types --- .../ProgressViewIOS/ProgressViewIOS.ios.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js b/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js index 1f6056535d619f..7b0bff3a248f8a 100644 --- a/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js +++ b/Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js @@ -21,8 +21,6 @@ import type {ImageSource} from 'ImageSource'; import type {ColorValue} from 'StyleSheetTypes'; import type {ViewProps} from 'ViewPropTypes'; -const RCTProgressView = requireNativeComponent('RCTProgressView'); - type Props = $ReadOnly<{| ...ViewProps, @@ -57,12 +55,18 @@ type Props = $ReadOnly<{| trackImage?: ?ImageSource, |}>; +type NativeProgressViewIOS = Class>; + +const RCTProgressView = ((requireNativeComponent( + 'RCTProgressView', +): any): NativeProgressViewIOS); + /** * Use `ProgressViewIOS` to render a UIProgressView on iOS. */ const ProgressViewIOS = ( props: Props, - forwardedRef?: ?React.Ref<'RCTProgressView'>, + forwardedRef?: ?React.Ref, ) => ( >); +module.exports = (ProgressViewIOSWithRef: NativeProgressViewIOS);