From 86be6f546dd4d165f6ac6a008d46969c4ec6cd69 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Tue, 17 Oct 2017 10:59:01 -0700 Subject: [PATCH] Delegate to ProgressBarAndroid from ActivityIndicator on Android, instead of the other way around - For context, see https://github.com/facebook/react-native/commit/ccddbf82d79833702f19d9f6ed1ca23755655187 --- .../ActivityIndicator/ActivityIndicator.js | 38 ++++++++----------- .../ProgressBarAndroid.android.js | 25 +++++++++++- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.js index 1ed1a7ebcc3e2d..3a47a3d8f4f9b3 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -14,8 +14,9 @@ const ColorPropType = require('ColorPropType'); const NativeMethodsMixin = require('NativeMethodsMixin'); const Platform = require('Platform'); -const React = require('React'); +const ProgressBarAndroid = require('ProgressBarAndroid'); const PropTypes = require('prop-types'); +const React = require('React'); const StyleSheet = require('StyleSheet'); const View = require('View'); const ViewPropTypes = require('ViewPropTypes'); @@ -135,16 +136,20 @@ const ActivityIndicator = createReactClass({ break; } + const nativeProps = { + ...props, + style: sizeStyle, + styleAttr: 'Normal', + indeterminate: true, + }; + return ( - - + + {Platform.OS === 'ios' ? ( + + ) : ( + + )} ); } @@ -169,18 +174,7 @@ if (Platform.OS === 'ios') { var RCTActivityIndicator = requireNativeComponent( 'RCTActivityIndicatorView', ActivityIndicator, - {nativeOnly: {activityIndicatorViewStyle: true}}, - ); -} else if (Platform.OS === 'android') { - var RCTActivityIndicator = requireNativeComponent( - 'AndroidProgressBar', - ActivityIndicator, - // Ignore props that are specific to non inderterminate ProgressBar. - {nativeOnly: { - indeterminate: true, - progress: true, - styleAttr: true, - }}, + { nativeOnly: { activityIndicatorViewStyle: true } } ); } diff --git a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js index 21fc5185a611bd..d47eb1d4c45ed1 100644 --- a/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +++ b/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js @@ -17,6 +17,8 @@ const React = require('React'); const ReactNative = require('ReactNative'); const ViewPropTypes = require('ViewPropTypes'); +const requireNativeComponent = require('requireNativeComponent'); + const STYLE_ATTRIBUTES = [ 'Horizontal', 'Normal', @@ -78,6 +80,14 @@ class ProgressBarAndroid extends ReactNative.NativeComponent { * - LargeInverse */ styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES), + /** + * Whether to show the ProgressBar (true, the default) or hide it (false). + */ + animating: PropTypes.bool, + /** + * Style of the ProgressBar. + */ + style: ViewPropTypes.style, /** * If the progress bar will show indeterminate progress. Note that this * can only be false if styleAttr is Horizontal. @@ -99,7 +109,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent { static defaultProps = { styleAttr: 'Normal', - indeterminate: true + indeterminate: true, + animating: true, }; componentDidMount() { @@ -112,8 +123,18 @@ class ProgressBarAndroid extends ReactNative.NativeComponent { } render() { - return ; + return ; } } +const AndroidProgressBar = requireNativeComponent( + 'AndroidProgressBar', + ProgressBarAndroid, + { + nativeOnly: { + animating: true, + }, + } +); + module.exports = ProgressBarAndroid;