Skip to content

Commit 4153448

Browse files
committed
Accept number for size prop
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 to define ActivityIndicator's size.
1 parent abe9f51 commit 4153448

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ const ActivityIndicator = React.createClass({
4141
color: ColorPropType,
4242
/**
4343
* 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.
44+
* Other sizes can be obtained by passing a number of by using a scale transform.
4545
*/
46-
size: PropTypes.oneOf([
47-
'small',
48-
'large',
46+
size: PropTypes.oneOfType([
47+
PropTypes.oneOf(['small','large',]),
48+
PropTypes.number,
4949
]),
5050
/**
5151
* Whether the indicator should hide when not animating (true by default).
@@ -67,24 +67,37 @@ const ActivityIndicator = React.createClass({
6767
render() {
6868
const {onLayout, style, ...props} = this.props;
6969
let sizeStyle;
70-
switch (props.size) {
71-
case 'small':
72-
sizeStyle = styles.sizeSmall;
73-
break;
74-
case 'large':
75-
sizeStyle = styles.sizeLarge;
76-
break;
70+
let ReturnedActivityIndicator;
71+
if (isNaN(props.size)) {
72+
switch (props.size) {
73+
case 'small':
74+
sizeStyle = styles.sizeSmall;
75+
break;
76+
case 'large':
77+
sizeStyle = styles.sizeLarge;
78+
break;
79+
}
80+
81+
ReturnedActivityIndicator = <RCTActivityIndicator
82+
{...props}
83+
style={sizeStyle}
84+
styleAttr='Normal'
85+
indeterminate
86+
/>;
87+
} else {
88+
ReturnedActivityIndicator = <RCTActivityIndicator
89+
{...props}
90+
style={ {height: props.size, width: props.size} }
91+
styleAttr='Normal'
92+
indeterminate
93+
/>;
7794
}
95+
7896
return (
7997
<View
8098
onLayout={onLayout}
8199
style={[styles.container, style]}>
82-
<RCTActivityIndicator
83-
{...props}
84-
style={sizeStyle}
85-
styleAttr="Normal"
86-
indeterminate
87-
/>
100+
{ReturnedActivityIndicator}
88101
</View>
89102
);
90103
}

0 commit comments

Comments
 (0)