Skip to content

Commit 93e6ae1

Browse files
empyricalfacebook-github-bot
authored andcommitted
ProgressViewIOS: Remove PropTypes and NativeMethodsMixin, convert to functional component (#21588)
Summary: This PR converts `ProgressViewIOS` from a `createReactClass` component to a functional component, and removes the remaining proptypes. Its use of `NativeMethodsMixin` has been ported to a `forwardRef` to the native component. Pull Request resolved: #21588 Reviewed By: hramos Differential Revision: D10338888 Pulled By: RSNara fbshipit-source-id: c49807e97a0e2cf774971d9aa5a8426f15a3e48d
1 parent 298f14d commit 93e6ae1

File tree

1 file changed

+46
-57
lines changed

1 file changed

+46
-57
lines changed

Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js

+46-57
Original file line numberDiff line numberDiff line change
@@ -10,89 +10,78 @@
1010

1111
'use strict';
1212

13-
const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
14-
const Image = require('Image');
15-
const NativeMethodsMixin = require('NativeMethodsMixin');
16-
const PropTypes = require('prop-types');
1713
const React = require('React');
18-
const ReactNative = require('ReactNative');
1914
const StyleSheet = require('StyleSheet');
2015

2116
const createReactClass = require('create-react-class');
2217
const requireNativeComponent = require('requireNativeComponent');
2318

19+
import type {NativeComponent} from 'ReactNative';
2420
import type {ImageSource} from 'ImageSource';
2521
import type {ColorValue} from 'StyleSheetTypes';
2622
import type {ViewProps} from 'ViewPropTypes';
2723

28-
const RCTProgressView = requireNativeComponent('RCTProgressView');
29-
3024
type Props = $ReadOnly<{|
3125
...ViewProps,
26+
27+
/**
28+
* The progress bar style.
29+
*/
3230
progressViewStyle?: ?('default' | 'bar'),
31+
32+
/**
33+
* The progress value (between 0 and 1).
34+
*/
3335
progress?: ?number,
36+
37+
/**
38+
* The tint color of the progress bar itself.
39+
*/
3440
progressTintColor?: ?ColorValue,
35-
trackTintColor?: ?string,
41+
42+
/**
43+
* The tint color of the progress bar track.
44+
*/
45+
trackTintColor?: ?ColorValue,
46+
47+
/**
48+
* A stretchable image to display as the progress bar.
49+
*/
3650
progressImage?: ?ImageSource,
51+
52+
/**
53+
* A stretchable image to display behind the progress bar.
54+
*/
3755
trackImage?: ?ImageSource,
3856
|}>;
3957

58+
type NativeProgressViewIOS = Class<NativeComponent<Props>>;
59+
60+
const RCTProgressView = ((requireNativeComponent(
61+
'RCTProgressView',
62+
): any): NativeProgressViewIOS);
63+
4064
/**
4165
* Use `ProgressViewIOS` to render a UIProgressView on iOS.
4266
*/
43-
const ProgressViewIOS = createReactClass({
44-
displayName: 'ProgressViewIOS',
45-
mixins: [NativeMethodsMixin],
46-
47-
propTypes: {
48-
...DeprecatedViewPropTypes,
49-
/**
50-
* The progress bar style.
51-
*/
52-
progressViewStyle: PropTypes.oneOf(['default', 'bar']),
53-
54-
/**
55-
* The progress value (between 0 and 1).
56-
*/
57-
progress: PropTypes.number,
58-
59-
/**
60-
* The tint color of the progress bar itself.
61-
*/
62-
progressTintColor: PropTypes.string,
63-
64-
/**
65-
* The tint color of the progress bar track.
66-
*/
67-
trackTintColor: PropTypes.string,
68-
69-
/**
70-
* A stretchable image to display as the progress bar.
71-
*/
72-
progressImage: Image.propTypes.source,
73-
74-
/**
75-
* A stretchable image to display behind the progress bar.
76-
*/
77-
trackImage: Image.propTypes.source,
78-
},
79-
80-
render: function() {
81-
return (
82-
<RCTProgressView
83-
{...this.props}
84-
style={[styles.progressView, this.props.style]}
85-
/>
86-
);
87-
},
88-
});
67+
const ProgressViewIOS = (
68+
props: Props,
69+
forwardedRef?: ?React.Ref<typeof RCTProgressView>,
70+
) => (
71+
<RCTProgressView
72+
{...props}
73+
style={[styles.progressView, props.style]}
74+
ref={forwardedRef}
75+
/>
76+
);
8977

9078
const styles = StyleSheet.create({
9179
progressView: {
9280
height: 2,
9381
},
9482
});
9583

96-
module.exports = ((ProgressViewIOS: any): Class<
97-
ReactNative.NativeComponent<Props>,
98-
>);
84+
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
85+
const ProgressViewIOSWithRef = React.forwardRef(ProgressViewIOS);
86+
87+
module.exports = (ProgressViewIOSWithRef: NativeProgressViewIOS);

0 commit comments

Comments
 (0)