Skip to content

Commit

Permalink
RN: Switch ProgressBarAndroid to React.forwardRef
Browse files Browse the repository at this point in the history
Reviewed By: sahrens

Differential Revision: D7904339

fbshipit-source-id: a4fe54acee7af12f1bc9b7c0d5e02a690f57ca0d
  • Loading branch information
yungsters authored and facebook-github-bot committed May 9, 2018
1 parent 8799047 commit 11cc7be
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

'use strict';

const ColorPropType = require('ColorPropType');
Expand All @@ -30,16 +32,18 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
const indeterminate = props[propName];
const styleAttr = props.styleAttr;
if (!indeterminate && styleAttr !== 'Horizontal') {
return new Error('indeterminate=false is only valid for styleAttr=Horizontal');
return new Error(
'indeterminate=false is only valid for styleAttr=Horizontal',
);
}
};

return PropTypes.bool(props, propName, componentName, ...rest) || checker();
};

/**
* React component that wraps the Android-only `ProgressBar`. This component is used to indicate
* that the app is loading or there is some activity in the app.
* React component that wraps the Android-only `ProgressBar`. This component is
* used to indicate that the app is loading or there is activity in the app.
*
* Example:
*
Expand All @@ -60,7 +64,7 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
* },
* ```
*/
class ProgressBarAndroid extends ReactNative.NativeComponent {
class ProgressBarAndroid extends React.Component {
static propTypes = {
...ViewPropTypes,

Expand Down Expand Up @@ -106,7 +110,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
};

render() {
return <AndroidProgressBar {...this.props} />;
const {forwardedRef, ...props} = this.props;
return <AndroidProgressBar {...props} ref={forwardedRef} />;
}
}

Expand All @@ -117,7 +122,9 @@ const AndroidProgressBar = requireNativeComponent(
nativeOnly: {
animating: true,
},
}
},
);

module.exports = ProgressBarAndroid;
module.exports = React.forwardRef((props, ref) => (
<ProgressBarAndroid {...props} forwardedRef={ref} />
));

0 comments on commit 11cc7be

Please sign in to comment.