From 6ebcd8122aaef461b33b57dd8f79d88ebfee9973 Mon Sep 17 00:00:00 2001 From: Fadil Sutomo Date: Sun, 17 Jul 2016 14:38:59 +0700 Subject: [PATCH 1/2] Accept number for size prop on Android 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. Not yet supported on iOS. --- .../ActivityIndicator/ActivityIndicator.js | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.js index 282960556e31..94e41c3062c8 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -23,6 +23,15 @@ const requireNativeComponent = require('requireNativeComponent'); const GRAY = '#999999'; +type IndicatorSize = number | 'small' | 'large'; + +type DefaultProps = { + animating: boolean; + color: any; + hidesWhenStopped: boolean; + size: IndicatorSize; +} + /** * Displays a circular loading indicator. */ @@ -40,12 +49,12 @@ 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. + * Size of the indicator (default is 'small'). + * Passing a number to the size prop is only supported on Android. */ - 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). @@ -55,7 +64,7 @@ const ActivityIndicator = React.createClass({ hidesWhenStopped: PropTypes.bool, }, - getDefaultProps() { + getDefaultProps(): DefaultProps { return { animating: true, color: Platform.OS === 'ios' ? GRAY : undefined, @@ -67,6 +76,7 @@ const ActivityIndicator = React.createClass({ render() { const {onLayout, style, ...props} = this.props; let sizeStyle; + switch (props.size) { case 'small': sizeStyle = styles.sizeSmall; @@ -74,7 +84,11 @@ const ActivityIndicator = React.createClass({ case 'large': sizeStyle = styles.sizeLarge; break; + default: + sizeStyle = {height: props.size, width: props.size}; + break; } + return ( Date: Sun, 17 Jul 2016 14:57:40 +0700 Subject: [PATCH 2/2] Add examples with custom size number usage --- .../UIExplorer/js/ActivityIndicatorExample.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Examples/UIExplorer/js/ActivityIndicatorExample.js b/Examples/UIExplorer/js/ActivityIndicatorExample.js index 4832b1d0eb19..ae3edd729888 100644 --- a/Examples/UIExplorer/js/ActivityIndicatorExample.js +++ b/Examples/UIExplorer/js/ActivityIndicatorExample.js @@ -113,8 +113,8 @@ exports.examples = [ return ( ); } @@ -161,8 +161,21 @@ exports.examples = [ ); } }, + { + platform: 'android', + title: 'Custom size (size: 75)', + render() { + return ( + + ); + } + }, ]; + const styles = StyleSheet.create({ centering: { alignItems: 'center',