Skip to content

Commit 7bddfa5

Browse files
fadilsMorgan Pretty
authored andcommitted
Activity indicator: add size prop
Summary: **motivation** Previously, size can only accept either 'small' or 'large'. And to obtain a custom size, scale transformation is used. This is to let users to possibly pass number value directly to define ActivityIndicator's size. **Test plan** I have also modified the current example to reflect the new size prop in action. Closes facebook#8935 Differential Revision: D3637910 fbshipit-source-id: 6b8e1d4504964916df327b2d3eaaef1bb8cd5112
1 parent f92645f commit 7bddfa5

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

Examples/UIExplorer/js/ActivityIndicatorExample.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ exports.examples = [
113113
return (
114114
<ActivityIndicator
115115
style={[styles.centering, styles.gray]}
116-
color="white"
117116
size="large"
117+
color="white"
118118
/>
119119
);
120120
}
@@ -161,8 +161,21 @@ exports.examples = [
161161
);
162162
}
163163
},
164+
{
165+
platform: 'android',
166+
title: 'Custom size (size: 75)',
167+
render() {
168+
return (
169+
<ActivityIndicator
170+
style={styles.centering}
171+
size={75}
172+
/>
173+
);
174+
}
175+
},
164176
];
165177

178+
166179
const styles = StyleSheet.create({
167180
centering: {
168181
alignItems: 'center',

Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ const requireNativeComponent = require('requireNativeComponent');
2323

2424
const GRAY = '#999999';
2525

26+
type IndicatorSize = number | 'small' | 'large';
27+
28+
type DefaultProps = {
29+
animating: boolean;
30+
color: any;
31+
hidesWhenStopped: boolean;
32+
size: IndicatorSize;
33+
}
34+
2635
/**
2736
* Displays a circular loading indicator.
2837
*/
@@ -40,12 +49,12 @@ const ActivityIndicator = React.createClass({
4049
*/
4150
color: ColorPropType,
4251
/**
43-
* Size of the indicator. Small has a height of 20, large has a height of 36.
44-
* Other sizes can be obtained using a scale transform.
52+
* Size of the indicator (default is 'small').
53+
* Passing a number to the size prop is only supported on Android.
4554
*/
46-
size: PropTypes.oneOf([
47-
'small',
48-
'large',
55+
size: PropTypes.oneOfType([
56+
PropTypes.oneOf([ 'small', 'large' ]),
57+
PropTypes.number,
4958
]),
5059
/**
5160
* Whether the indicator should hide when not animating (true by default).
@@ -55,7 +64,7 @@ const ActivityIndicator = React.createClass({
5564
hidesWhenStopped: PropTypes.bool,
5665
},
5766

58-
getDefaultProps() {
67+
getDefaultProps(): DefaultProps {
5968
return {
6069
animating: true,
6170
color: Platform.OS === 'ios' ? GRAY : undefined,
@@ -67,14 +76,19 @@ const ActivityIndicator = React.createClass({
6776
render() {
6877
const {onLayout, style, ...props} = this.props;
6978
let sizeStyle;
79+
7080
switch (props.size) {
7181
case 'small':
7282
sizeStyle = styles.sizeSmall;
7383
break;
7484
case 'large':
7585
sizeStyle = styles.sizeLarge;
7686
break;
87+
default:
88+
sizeStyle = {height: props.size, width: props.size};
89+
break;
7790
}
91+
7892
return (
7993
<View
8094
onLayout={onLayout}

0 commit comments

Comments
 (0)