Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeMethodsMixin] ProgressViewIOS: Remove PropTypes and NativeMethodsMixin, convert to functional component #21588

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 40 additions & 55 deletions Libraries/Components/ProgressViewIOS/ProgressViewIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,70 +25,59 @@ 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 (
<RCTProgressView
{...this.props}
style={[styles.progressView, this.props.style]}
/>
);
},
});
const ProgressViewIOS = (
props: Props,
forwardedRef?: ?React.Ref<'RCTProgressView'>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way the other components (like Text) seem to do it - but I notice that View does it a better way, so I updated it to do it the way View does it. The other ones should be cleaned up too, perhaps!

) => (
<RCTProgressView
{...props}
style={[styles.progressView, props.style]}
ref={forwardedRef}
/>
);

const styles = StyleSheet.create({
progressView: {
height: 2,
},
});

module.exports = ((ProgressViewIOS: any): Class<
ReactNative.NativeComponent<Props>,
>);
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
const ProgressViewIOSWithRef = React.forwardRef(ProgressViewIOS);

module.exports = (ProgressViewIOSWithRef: Class<NativeComponent<Props>>);