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
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2016-05-26 20:46:58 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Platform = require('Platform');
|
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
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2018-05-12 17:25:12 +00:00
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
import type {NativeComponent} from 'ReactNative';
|
2018-05-12 17:25:12 +00:00
|
|
|
import type {ViewProps} from 'ViewPropTypes';
|
|
|
|
|
2018-06-01 19:37:22 +00:00
|
|
|
const RCTActivityIndicator =
|
|
|
|
Platform.OS === 'android'
|
|
|
|
? require('ProgressBarAndroid')
|
|
|
|
: requireNativeComponent('RCTActivityIndicatorView');
|
2016-05-26 20:46:58 +00:00
|
|
|
|
|
|
|
const GRAY = '#999999';
|
|
|
|
|
2016-07-28 22:14:59 +00:00
|
|
|
type IndicatorSize = number | 'small' | 'large';
|
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
type IOSProps = $ReadOnly<{|
|
|
|
|
/**
|
|
|
|
* Whether the indicator should hide when not animating (true by default).
|
|
|
|
*
|
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#hideswhenstopped
|
|
|
|
*/
|
|
|
|
hidesWhenStopped?: ?boolean,
|
|
|
|
|}>;
|
2018-05-12 17:25:12 +00:00
|
|
|
type Props = $ReadOnly<{|
|
|
|
|
...ViewProps,
|
2018-06-01 17:11:23 +00:00
|
|
|
...IOSProps,
|
2018-05-12 17:25:12 +00:00
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
/**
|
|
|
|
* Whether to show the indicator (true, the default) or hide it (false).
|
|
|
|
*
|
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#animating
|
|
|
|
*/
|
2018-05-12 17:25:12 +00:00
|
|
|
animating?: ?boolean,
|
2018-06-01 17:11:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The foreground color of the spinner (default is gray).
|
|
|
|
*
|
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#color
|
|
|
|
*/
|
2018-05-12 17:25:12 +00:00
|
|
|
color?: ?string,
|
2018-06-01 17:11:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Size of the indicator (default is 'small').
|
|
|
|
* Passing a number to the size prop is only supported on Android.
|
|
|
|
*
|
|
|
|
* See http://facebook.github.io/react-native/docs/activityindicator.html#size
|
|
|
|
*/
|
2018-05-12 17:25:12 +00:00
|
|
|
size?: ?IndicatorSize,
|
|
|
|
|}>;
|
|
|
|
|
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
|
|
|
*/
|
2018-06-01 17:11:23 +00:00
|
|
|
const ActivityIndicator = (
|
2018-06-19 21:13:03 +00:00
|
|
|
props: Props,
|
|
|
|
forwardedRef?: ?React.Ref<'RCTActivityIndicatorView'>,
|
2018-06-01 17:11:23 +00:00
|
|
|
) => {
|
2018-06-19 21:13:03 +00:00
|
|
|
const {onLayout, style, ...restProps} = props;
|
2018-06-01 17:11:23 +00:00
|
|
|
let sizeStyle;
|
|
|
|
|
|
|
|
switch (props.size) {
|
|
|
|
case 'small':
|
|
|
|
sizeStyle = styles.sizeSmall;
|
|
|
|
break;
|
|
|
|
case 'large':
|
|
|
|
sizeStyle = styles.sizeLarge;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sizeStyle = {height: props.size, width: props.size};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nativeProps = {
|
|
|
|
...restProps,
|
|
|
|
ref: forwardedRef,
|
|
|
|
style: sizeStyle,
|
|
|
|
styleAttr: 'Normal',
|
|
|
|
indeterminate: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2018-06-19 21:13:03 +00:00
|
|
|
<View
|
|
|
|
onLayout={onLayout}
|
|
|
|
style={StyleSheet.compose(
|
|
|
|
styles.container,
|
|
|
|
style,
|
|
|
|
)}>
|
2018-08-13 18:14:35 +00:00
|
|
|
{/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
|
|
|
|
* found when making Flow check .android.js files. */}
|
2018-06-01 19:37:22 +00:00
|
|
|
<RCTActivityIndicator {...nativeProps} />
|
2018-06-01 17:11:23 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
2018-06-12 03:44:49 +00:00
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
// $FlowFixMe - TODO T29156721 `React.forwardRef` is not defined in Flow, yet.
|
2018-06-19 21:13:03 +00:00
|
|
|
const ActivityIndicatorWithRef = React.forwardRef(ActivityIndicator);
|
2016-05-26 20:46:58 +00:00
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
ActivityIndicatorWithRef.defaultProps = {
|
|
|
|
animating: true,
|
|
|
|
color: Platform.OS === 'ios' ? GRAY : null,
|
|
|
|
hidesWhenStopped: true,
|
|
|
|
size: 'small',
|
|
|
|
};
|
2016-05-26 20:46:58 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
|
|
|
sizeSmall: {
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
},
|
|
|
|
sizeLarge: {
|
|
|
|
width: 36,
|
|
|
|
height: 36,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-06-01 17:11:23 +00:00
|
|
|
module.exports = (ActivityIndicatorWithRef: Class<NativeComponent<Props>>);
|