2016-05-26 20:46:58 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-05-26 20:46:58 +00:00
|
|
|
*
|
|
|
|
* @providesModule ActivityIndicator
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const ColorPropType = require('ColorPropType');
|
2016-11-04 12:40:26 +00:00
|
|
|
const NativeMethodsMixin = require('NativeMethodsMixin');
|
2016-05-26 20:46:58 +00:00
|
|
|
const Platform = require('Platform');
|
2017-10-18 23:50:41 +00:00
|
|
|
const ProgressBarAndroid = require('ProgressBarAndroid');
|
2017-10-18 19:46:43 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2017-10-18 23:50:41 +00:00
|
|
|
const React = require('React');
|
2016-05-26 20:46:58 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const View = require('View');
|
2017-03-24 07:22:57 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
|
|
|
|
2017-07-07 21:24:25 +00:00
|
|
|
const createReactClass = require('create-react-class');
|
2016-05-26 20:46:58 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
|
|
|
|
|
|
|
const GRAY = '#999999';
|
|
|
|
|
2016-07-28 22:14:59 +00:00
|
|
|
type IndicatorSize = number | 'small' | 'large';
|
|
|
|
|
|
|
|
type DefaultProps = {
|
2016-08-09 13:32:41 +00:00
|
|
|
animating: boolean,
|
|
|
|
color: any,
|
|
|
|
hidesWhenStopped: boolean,
|
|
|
|
size: IndicatorSize,
|
2016-07-28 22:14:59 +00:00
|
|
|
}
|
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
/**
|
|
|
|
* Displays a circular loading indicator.
|
2017-09-22 00:31:53 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html
|
2016-05-26 20:46:58 +00:00
|
|
|
*/
|
2017-07-07 21:24:25 +00:00
|
|
|
const ActivityIndicator = createReactClass({
|
|
|
|
displayName: 'ActivityIndicator',
|
2016-05-26 20:46:58 +00:00
|
|
|
mixins: [NativeMethodsMixin],
|
|
|
|
|
|
|
|
propTypes: {
|
2017-03-24 07:22:57 +00:00
|
|
|
...ViewPropTypes,
|
2016-05-26 20:46:58 +00:00
|
|
|
/**
|
|
|
|
* Whether to show the indicator (true, the default) or hide it (false).
|
2018-02-22 15:04:35 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#animating
|
2016-05-26 20:46:58 +00:00
|
|
|
*/
|
|
|
|
animating: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* The foreground color of the spinner (default is gray).
|
2018-02-22 15:04:35 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#color
|
2016-05-26 20:46:58 +00:00
|
|
|
*/
|
|
|
|
color: ColorPropType,
|
|
|
|
/**
|
2016-07-28 22:14:59 +00:00
|
|
|
* Size of the indicator (default is 'small').
|
|
|
|
* Passing a number to the size prop is only supported on Android.
|
2018-02-22 15:04:35 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#size
|
2016-05-26 20:46:58 +00:00
|
|
|
*/
|
2016-07-28 22:14:59 +00:00
|
|
|
size: PropTypes.oneOfType([
|
|
|
|
PropTypes.oneOf([ 'small', 'large' ]),
|
|
|
|
PropTypes.number,
|
2016-05-26 20:46:58 +00:00
|
|
|
]),
|
|
|
|
/**
|
|
|
|
* Whether the indicator should hide when not animating (true by default).
|
|
|
|
*
|
|
|
|
* @platform ios
|
2018-02-22 15:04:35 +00:00
|
|
|
*
|
Migrate to new documentation format
Summary:
Now that the Component and API docs are no longer auto-generated, we need to consolidate on a new format for our jsdoc comments. Any help from the community will be appreciated.
In this initial pull request, we'll be tackling the following docs:
- `AccessibilityInfo`, an API doc.
- `ActivityIndicator`, a Component doc.
- `View`, a Component doc.
This top comment will serve as a style guide, and when in doubt, please refer to the individual commits in this PR.
Each commit should update a single component or API, along with any relevant markdown files.
- Documentation in the JavaScript source files should be succinct. Any verbosity should be moved over to the markdown docs in the website...
- ...by adding a link to the relevant method/prop on the website to every comment block.
- Avoid markdown style links in JavaScript source files, opt for plain old URIs.
Let code document itself:
- If a method is Flow typed, the comment block does not need to repeat this information.
- If a param can be one of several values, and the type definition is easily determined from the code, the values should not be repeated in the comment block. Again, move this to the markdown doc if not present already.
Closes https://github.com/facebook/react-native/pull/16790
Differential Revision: D6353840
Pulled By: hramos
fbshipit-source-id: 9712c459acc33092aae9909f3dd0b58a00b26afc
2017-11-17 00:44:29 +00:00
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#hideswhenstopped
|
2016-05-26 20:46:58 +00:00
|
|
|
*/
|
|
|
|
hidesWhenStopped: PropTypes.bool,
|
|
|
|
},
|
|
|
|
|
2016-07-28 22:14:59 +00:00
|
|
|
getDefaultProps(): DefaultProps {
|
2016-05-26 20:46:58 +00:00
|
|
|
return {
|
|
|
|
animating: true,
|
2016-06-14 05:15:47 +00:00
|
|
|
color: Platform.OS === 'ios' ? GRAY : undefined,
|
2016-05-26 20:46:58 +00:00
|
|
|
hidesWhenStopped: true,
|
|
|
|
size: 'small',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {onLayout, style, ...props} = this.props;
|
|
|
|
let sizeStyle;
|
2016-07-28 22:14:59 +00:00
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
switch (props.size) {
|
|
|
|
case 'small':
|
|
|
|
sizeStyle = styles.sizeSmall;
|
|
|
|
break;
|
|
|
|
case 'large':
|
|
|
|
sizeStyle = styles.sizeLarge;
|
|
|
|
break;
|
2016-07-28 22:14:59 +00:00
|
|
|
default:
|
|
|
|
sizeStyle = {height: props.size, width: props.size};
|
|
|
|
break;
|
2016-05-26 20:46:58 +00:00
|
|
|
}
|
2016-07-28 22:14:59 +00:00
|
|
|
|
2017-10-18 23:50:41 +00:00
|
|
|
const nativeProps = {
|
|
|
|
...props,
|
|
|
|
style: sizeStyle,
|
|
|
|
styleAttr: 'Normal',
|
|
|
|
indeterminate: true,
|
|
|
|
};
|
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
return (
|
2017-10-18 23:50:41 +00:00
|
|
|
<View onLayout={onLayout} style={[styles.container, style]}>
|
|
|
|
{Platform.OS === 'ios' ? (
|
|
|
|
<RCTActivityIndicator {...nativeProps} />
|
|
|
|
) : (
|
|
|
|
<ProgressBarAndroid {...nativeProps} />
|
|
|
|
)}
|
2016-05-26 20:46:58 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
sizeSmall: {
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
},
|
|
|
|
sizeLarge: {
|
|
|
|
width: 36,
|
|
|
|
height: 36,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
var RCTActivityIndicator = requireNativeComponent(
|
|
|
|
'RCTActivityIndicatorView',
|
|
|
|
ActivityIndicator,
|
2017-10-18 23:50:41 +00:00
|
|
|
{ nativeOnly: { activityIndicatorViewStyle: true } }
|
2016-05-26 20:46:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ActivityIndicator;
|