Skip to content

Commit 78281ec

Browse files
committed
Delegate to ProgressBarAndroid from ActivityIndicator on Android, instead of the other way around
- For context, see ccddbf8
1 parent 91372e8 commit 78281ec

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
const ColorPropType = require('ColorPropType');
1515
const NativeMethodsMixin = require('NativeMethodsMixin');
1616
const Platform = require('Platform');
17-
const React = require('React');
17+
const ProgressBarAndroid = require('ProgressBarAndroid');
1818
const PropTypes = require('prop-types');
19+
const React = require('React');
1920
const StyleSheet = require('StyleSheet');
2021
const View = require('View');
2122
const ViewPropTypes = require('ViewPropTypes');
@@ -135,16 +136,20 @@ const ActivityIndicator = createReactClass({
135136
break;
136137
}
137138

139+
const nativeProps = {
140+
...props,
141+
style: sizeStyle,
142+
styleAttr: 'Normal',
143+
indeterminate: true,
144+
};
145+
138146
return (
139-
<View
140-
onLayout={onLayout}
141-
style={[styles.container, style]}>
142-
<RCTActivityIndicator
143-
{...props}
144-
style={sizeStyle}
145-
styleAttr="Normal"
146-
indeterminate
147-
/>
147+
<View onLayout={onLayout} style={[styles.container, style]}>
148+
{Platform.OS === 'ios' ? (
149+
<RCTActivityIndicator {...nativeProps} />
150+
) : (
151+
<ProgressBarAndroid {...nativeProps} />
152+
)}
148153
</View>
149154
);
150155
}
@@ -169,18 +174,7 @@ if (Platform.OS === 'ios') {
169174
var RCTActivityIndicator = requireNativeComponent(
170175
'RCTActivityIndicatorView',
171176
ActivityIndicator,
172-
{nativeOnly: {activityIndicatorViewStyle: true}},
173-
);
174-
} else if (Platform.OS === 'android') {
175-
var RCTActivityIndicator = requireNativeComponent(
176-
'AndroidProgressBar',
177-
ActivityIndicator,
178-
// Ignore props that are specific to non inderterminate ProgressBar.
179-
{nativeOnly: {
180-
indeterminate: true,
181-
progress: true,
182-
styleAttr: true,
183-
}},
177+
{ nativeOnly: { activityIndicatorViewStyle: true } }
184178
);
185179
}
186180

Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const React = require('React');
1717
const ReactNative = require('ReactNative');
1818
const ViewPropTypes = require('ViewPropTypes');
1919

20+
const requireNativeComponent = require('requireNativeComponent');
21+
2022
const STYLE_ATTRIBUTES = [
2123
'Horizontal',
2224
'Normal',
@@ -78,6 +80,19 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
7880
* - LargeInverse
7981
*/
8082
styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES),
83+
/**
84+
* Whether to show the ProgressBar (true, the default) or hide it (false).
85+
*/
86+
animating: PropTypes.bool,
87+
/**
88+
* Size of the indicator (default is 'small'). Note that this is ignored
89+
* unless styleAttr is Regular.
90+
*/
91+
style: PropTypes.oneOfType([
92+
ViewPropTypes.style,
93+
PropTypes.oneOf(['small', 'large']),
94+
PropTypes.number,
95+
]),
8196
/**
8297
* If the progress bar will show indeterminate progress. Note that this
8398
* can only be false if styleAttr is Horizontal.
@@ -99,7 +114,8 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
99114

100115
static defaultProps = {
101116
styleAttr: 'Normal',
102-
indeterminate: true
117+
indeterminate: true,
118+
animating: true,
103119
};
104120

105121
componentDidMount() {
@@ -112,8 +128,18 @@ class ProgressBarAndroid extends ReactNative.NativeComponent {
112128
}
113129

114130
render() {
115-
return <ActivityIndicator {...this.props} animating={true} />;
131+
return <AndroidProgressBar {...this.props} />;
116132
}
117133
}
118134

135+
const AndroidProgressBar = requireNativeComponent(
136+
'AndroidProgressBar',
137+
ProgressBarAndroid,
138+
{
139+
nativeOnly: {
140+
animating: true,
141+
},
142+
}
143+
);
144+
119145
module.exports = ProgressBarAndroid;

0 commit comments

Comments
 (0)