RN: Switch ProgressBarAndroid to React.forwardRef

Reviewed By: sahrens

Differential Revision: D7904339

fbshipit-source-id: a4fe54acee7af12f1bc9b7c0d5e02a690f57ca0d
This commit is contained in:
Tim Yung 2018-05-09 15:18:18 -07:00 committed by Facebook Github Bot
parent 8799047dd0
commit 11cc7be821

View File

@ -4,7 +4,9 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @format
*/ */
'use strict'; 'use strict';
const ColorPropType = require('ColorPropType'); const ColorPropType = require('ColorPropType');
@ -30,7 +32,9 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
const indeterminate = props[propName]; const indeterminate = props[propName];
const styleAttr = props.styleAttr; const styleAttr = props.styleAttr;
if (!indeterminate && styleAttr !== 'Horizontal') { 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',
);
} }
}; };
@ -38,8 +42,8 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
}; };
/** /**
* React component that wraps the Android-only `ProgressBar`. This component is used to indicate * React component that wraps the Android-only `ProgressBar`. This component is
* that the app is loading or there is some activity in the app. * used to indicate that the app is loading or there is activity in the app.
* *
* Example: * Example:
* *
@ -60,7 +64,7 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
* }, * },
* ``` * ```
*/ */
class ProgressBarAndroid extends ReactNative.NativeComponent { class ProgressBarAndroid extends React.Component {
static propTypes = { static propTypes = {
...ViewPropTypes, ...ViewPropTypes,
@ -106,7 +110,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
}; };
render() { render() {
return <AndroidProgressBar {...this.props} />; const {forwardedRef, ...props} = this.props;
return <AndroidProgressBar {...props} ref={forwardedRef} />;
} }
} }
@ -117,7 +122,9 @@ const AndroidProgressBar = requireNativeComponent(
nativeOnly: { nativeOnly: {
animating: true, animating: true,
}, },
} },
); );
module.exports = ProgressBarAndroid; module.exports = React.forwardRef((props, ref) => (
<ProgressBarAndroid {...props} forwardedRef={ref} />
));