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 коммит произвёл Facebook Github Bot
Родитель 8799047dd0
Коммит 11cc7be821
1 изменённых файлов: 14 добавлений и 7 удалений

Просмотреть файл

@ -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');
@ -30,7 +32,9 @@ 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',
);
}
};
@ -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
* 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:
*
@ -60,7 +64,7 @@ const indeterminateType = function(props, propName, componentName, ...rest) {
* },
* ```
*/
class ProgressBarAndroid extends ReactNative.NativeComponent {
class ProgressBarAndroid extends React.Component {
static propTypes = {
...ViewPropTypes,
@ -106,7 +110,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
};
render() {
return <AndroidProgressBar {...this.props} />;
const {forwardedRef, ...props} = this.props;
return <AndroidProgressBar {...props} ref={forwardedRef} />;
}
}
@ -117,7 +122,9 @@ const AndroidProgressBar = requireNativeComponent(
nativeOnly: {
animating: true,
},
}
},
);
module.exports = ProgressBarAndroid;
module.exports = React.forwardRef((props, ref) => (
<ProgressBarAndroid {...props} forwardedRef={ref} />
));