Improved RCTActivityIndicatorView and fixed some flow errors

This commit is contained in:
Nick Lockwood
2015-04-26 02:22:34 -07:00
parent dd6bce78e1
commit 77e38b26c5
7 changed files with 46 additions and 56 deletions

View File

@@ -18,21 +18,16 @@ var React = require('React');
var StyleSheet = require('StyleSheet');
var View = require('View');
var keyMirror = require('keyMirror');
var requireNativeComponent = require('requireNativeComponent');
var verifyPropTypes = require('verifyPropTypes');
var SpinnerSize = keyMirror({
large: null,
small: null,
});
var GRAY = '#999999';
type DefaultProps = {
animating: boolean;
size: 'small' | 'large';
color: string;
hidesWhenStopped: boolean;
size: 'small' | 'large';
};
var ActivityIndicatorIOS = React.createClass({
@@ -47,7 +42,10 @@ var ActivityIndicatorIOS = React.createClass({
* The foreground color of the spinner (default is gray).
*/
color: PropTypes.string,
/**
* Whether the indicator should hide when not animating (true by default).
*/
hidesWhenStopped: PropTypes.bool,
/**
* Size of the indicator. Small has a height of 20, large has a height of 36.
*/
@@ -60,27 +58,18 @@ var ActivityIndicatorIOS = React.createClass({
getDefaultProps: function(): DefaultProps {
return {
animating: true,
size: SpinnerSize.small,
color: GRAY,
hidesWhenStopped: true,
size: 'small',
};
},
render: function() {
var style = styles.sizeSmall;
var NativeConstants = NativeModules.UIManager.UIActivityIndicatorView.Constants;
var activityIndicatorViewStyle = NativeConstants.StyleWhite;
if (this.props.size === 'large') {
style = styles.sizeLarge;
activityIndicatorViewStyle = NativeConstants.StyleWhiteLarge;
}
var {style, ...props} = this.props;
var sizeStyle = (this.props.size === 'large') ? styles.sizeLarge : styles.sizeSmall;
return (
<View
style={[styles.container, style, this.props.style]}>
<UIActivityIndicatorView
activityIndicatorViewStyle={activityIndicatorViewStyle}
animating={this.props.animating}
color={this.props.color}
/>
<View style={[styles.container, sizeStyle, style]}>
<RCTActivityIndicatorView {...props} />
</View>
);
}
@@ -99,15 +88,15 @@ var styles = StyleSheet.create({
}
});
var UIActivityIndicatorView = requireNativeComponent(
'UIActivityIndicatorView',
var RCTActivityIndicatorView = requireNativeComponent(
'RCTActivityIndicatorView',
null
);
if (__DEV__) {
var nativeOnlyProps = {activityIndicatorViewStyle: true};
verifyPropTypes(
ActivityIndicatorIOS,
UIActivityIndicatorView.viewConfig,
RCTActivityIndicatorView.viewConfig,
nativeOnlyProps
);
}

View File

@@ -66,6 +66,9 @@ var TabBarItemIOS = React.createClass({
* blank content, you probably forgot to add a selected one.
*/
selected: React.PropTypes.bool,
/**
* React style object.
*/
style: View.propTypes.style,
/**
* Text that appears under the icon. It is ignored when a system icon
@@ -86,7 +89,7 @@ var TabBarItemIOS = React.createClass({
}
},
componentWillReceiveProps: function(nextProps: { selected: boolean }) {
componentWillReceiveProps: function(nextProps: { selected: any /* workaround for flow bug */ }) {
if (this.state.hasBeenSelected || nextProps.selected) {
this.setState({hasBeenSelected: true});
}

View File

@@ -191,10 +191,10 @@ var ReactIOSMount = {
* that has been rendered and unmounting it. There should just be one child
* component at this time.
*/
unmountComponentAtNode: function(containerTag: number): bool {
unmountComponentAtNode: function(containerTag: number): boolean {
if (!ReactIOSTagHandles.reactTagIsNativeTopRootID(containerTag)) {
console.error('You cannot render into anything but a top root');
return;
return false;
}
var containerID = ReactIOSTagHandles.tagToRootNodeID[containerTag];