2015-09-14 14:35: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.
|
2015-09-14 14:35:58 +00:00
|
|
|
*
|
2018-05-09 22:18:18 +00:00
|
|
|
* @format
|
2015-09-14 14:35:58 +00:00
|
|
|
*/
|
2018-05-09 22:18:18 +00:00
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
const ColorPropType = require('ColorPropType');
|
|
|
|
const PropTypes = require('prop-types');
|
2017-09-19 06:45:19 +00:00
|
|
|
const React = require('React');
|
2018-06-12 03:44:49 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-10-18 23:50:41 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
const STYLE_ATTRIBUTES = [
|
|
|
|
'Horizontal',
|
|
|
|
'Normal',
|
|
|
|
'Small',
|
|
|
|
'Large',
|
|
|
|
'Inverse',
|
|
|
|
'SmallInverse',
|
|
|
|
'LargeInverse',
|
|
|
|
];
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
const indeterminateType = function(props, propName, componentName, ...rest) {
|
|
|
|
const checker = function() {
|
|
|
|
const indeterminate = props[propName];
|
|
|
|
const styleAttr = props.styleAttr;
|
|
|
|
if (!indeterminate && styleAttr !== 'Horizontal') {
|
|
|
|
return new Error(
|
|
|
|
'indeterminate=false is only valid for styleAttr=Horizontal',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
return PropTypes.bool(props, propName, componentName, ...rest) || checker();
|
|
|
|
};
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2018-05-09 22:18:18 +00:00
|
|
|
* React component that wraps the Android-only `ProgressBar`. This component is
|
|
|
|
* used to indicate that the app is loading or there is activity in the app.
|
2015-09-14 14:35:58 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* render: function() {
|
|
|
|
* var progressBar =
|
|
|
|
* <View style={styles.container}>
|
|
|
|
* <ProgressBar styleAttr="Inverse" />
|
|
|
|
* </View>;
|
|
|
|
|
|
|
|
* return (
|
|
|
|
* <MyLoadingComponent
|
|
|
|
* componentView={componentView}
|
|
|
|
* loadingView={progressBar}
|
|
|
|
* style={styles.loadingComponent}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* },
|
|
|
|
* ```
|
|
|
|
*/
|
2018-06-12 03:44:49 +00:00
|
|
|
class ProgressBarAndroid extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
...ViewPropTypes,
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
/**
|
|
|
|
* Style of the ProgressBar. One of:
|
|
|
|
*
|
|
|
|
* - Horizontal
|
|
|
|
* - Normal (default)
|
|
|
|
* - Small
|
|
|
|
* - Large
|
|
|
|
* - Inverse
|
|
|
|
* - SmallInverse
|
|
|
|
* - LargeInverse
|
|
|
|
*/
|
|
|
|
styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES),
|
|
|
|
/**
|
|
|
|
* Whether to show the ProgressBar (true, the default) or hide it (false).
|
|
|
|
*/
|
|
|
|
animating: PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* If the progress bar will show indeterminate progress. Note that this
|
|
|
|
* can only be false if styleAttr is Horizontal.
|
|
|
|
*/
|
|
|
|
indeterminate: indeterminateType,
|
|
|
|
/**
|
|
|
|
* The progress value (between 0 and 1).
|
|
|
|
*/
|
|
|
|
progress: PropTypes.number,
|
|
|
|
/**
|
|
|
|
* Color of the progress bar.
|
|
|
|
*/
|
|
|
|
color: ColorPropType,
|
|
|
|
/**
|
|
|
|
* Used to locate this view in end-to-end tests.
|
|
|
|
*/
|
|
|
|
testID: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
styleAttr: 'Normal',
|
|
|
|
indeterminate: true,
|
|
|
|
animating: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {forwardedRef, ...props} = this.props;
|
|
|
|
return <AndroidProgressBar {...props} ref={forwardedRef} />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const AndroidProgressBar = requireNativeComponent('AndroidProgressBar');
|
2017-10-18 23:50:41 +00:00
|
|
|
|
2018-06-12 03:44:49 +00:00
|
|
|
module.exports = React.forwardRef((props, ref) => (
|
|
|
|
<ProgressBarAndroid {...props} forwardedRef={ref} />
|
|
|
|
));
|