Skip to content

Commit

Permalink
Accept number for size prop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fadils committed Jul 17, 2016
1 parent abe9f51 commit b4dc4ed
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions Libraries/Components/ActivityIndicator/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const ActivityIndicator = React.createClass({
color: ColorPropType,
/**
* Size of the indicator. Small has a height of 20, large has a height of 36.
* Other sizes can be obtained using a scale transform.
* Other sizes can be obtained by passing a number of by using a scale transform.
*/
size: PropTypes.oneOf([
'small',
'large',
size: PropTypes.oneOfType([
PropTypes.oneOf(['small','large',]),
PropTypes.number,
]),
/**
* Whether the indicator should hide when not animating (true by default).
Expand All @@ -67,24 +67,37 @@ const ActivityIndicator = React.createClass({
render() {
const {onLayout, style, ...props} = this.props;
let sizeStyle;
switch (props.size) {
case 'small':
sizeStyle = styles.sizeSmall;
break;
case 'large':
sizeStyle = styles.sizeLarge;
break;
let ReturnedActivityIndicator;
if (isNaN(props.size)) {
switch (props.size) {
case 'small':
sizeStyle = styles.sizeSmall;
break;
case 'large':
sizeStyle = styles.sizeLarge;
break;
}

ReturnedActivityIndicator = <RCTActivityIndicator
{...props}
style={sizeStyle}
styleAttr="Normal"
indeterminate
/>;
} else {
ReturnedActivityIndicator = <RCTActivityIndicator
{...props}
style={ {height: props.size, width: props.size} }
styleAttr="Normal"
indeterminate
/>;
}

return (
<View
onLayout={onLayout}
style={[styles.container, style]}>
<RCTActivityIndicator
{...props}
style={sizeStyle}
styleAttr="Normal"
indeterminate
/>
{ReturnedActivityIndicator}
</View>
);
}
Expand Down

0 comments on commit b4dc4ed

Please sign in to comment.