From 504528bcbf112d2c12fefc975f38d409cba488d1 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Tue, 17 Oct 2017 20:25:59 -0700 Subject: [PATCH] Delegate to ProgressBarAndroid from ActivityIndicator on Android, instead of the other way around MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: `ProgressBarAndroid` regressed after fixing a bug in https://github.com/facebook/react-native/commit/ccddbf82d79833702f19d9f6ed1ca23755655187 Run this gist on a new project with this code: https://gist.github.com/brentvatne/a0b57e5bbae1bd2cf76765ea27f077af Notice that you will see: screen shot 2017-10-17 at 11 06 03 am hmmm... doesn't seem right � With the patch in this PR applied, you will see: screen shot 2017-10-17 at 11 01 38 am oh! there we go 😄 [ANDROID] [BUGFIX] [ProgressBarAndroid] - Fix regression in ProgressBarAndroid which limited `styleAttr` to only `Regular`. Closes https://github.com/facebook/react-native/pull/16435 Differential Revision: D6080118 Pulled By: hramos fbshipit-source-id: 537ee2c96deedd7b2e75ff3dbdefc1506812f3f3 --- .../ActivityIndicator/ActivityIndicator.js | 38 ++++++++----------- .../ProgressBarAndroid.android.js | 21 +++++++++- 2 files changed, 35 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..de5e0e52e35c40 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,10 @@ 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, /** * If the progress bar will show indeterminate progress. Note that this * can only be false if styleAttr is Horizontal. @@ -99,7 +105,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent { static defaultProps = { styleAttr: 'Normal', - indeterminate: true + indeterminate: true, + animating: true, }; componentDidMount() { @@ -112,8 +119,18 @@ class ProgressBarAndroid extends ReactNative.NativeComponent { } render() { - return ; + return ; } } +const AndroidProgressBar = requireNativeComponent( + 'AndroidProgressBar', + ProgressBarAndroid, + { + nativeOnly: { + animating: true, + }, + } +); + module.exports = ProgressBarAndroid;