2015-09-14 14:35:58 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule ProgressBarAndroid
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-09-19 06:45:19 +00:00
|
|
|
const ColorPropType = require('ColorPropType');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const React = require('React');
|
|
|
|
const ReactNative = require('ReactNative');
|
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-10-18 23:50:41 +00:00
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
|
|
|
|
2017-09-19 06:45:19 +00:00
|
|
|
const STYLE_ATTRIBUTES = [
|
2015-09-14 14:35:58 +00:00
|
|
|
'Horizontal',
|
2016-01-07 16:44:14 +00:00
|
|
|
'Normal',
|
2015-09-14 14:35:58 +00:00
|
|
|
'Small',
|
|
|
|
'Large',
|
|
|
|
'Inverse',
|
|
|
|
'SmallInverse',
|
2016-10-15 01:50:17 +00:00
|
|
|
'LargeInverse',
|
2015-09-14 14:35:58 +00:00
|
|
|
];
|
|
|
|
|
2017-09-19 06:45:19 +00:00
|
|
|
const indeterminateType = function(props, propName, componentName, ...rest) {
|
|
|
|
const checker = function() {
|
|
|
|
const indeterminate = props[propName];
|
|
|
|
const styleAttr = props.styleAttr;
|
2015-11-06 20:07:54 +00:00
|
|
|
if (!indeterminate && styleAttr !== 'Horizontal') {
|
|
|
|
return new Error('indeterminate=false is only valid for styleAttr=Horizontal');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-10 12:14:55 +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
|
|
|
/**
|
|
|
|
* React component that wraps the Android-only `ProgressBar`. This component is used to indicate
|
|
|
|
* that the app is loading or there is some activity in the app.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* render: function() {
|
|
|
|
* var progressBar =
|
|
|
|
* <View style={styles.container}>
|
|
|
|
* <ProgressBar styleAttr="Inverse" />
|
|
|
|
* </View>;
|
|
|
|
|
|
|
|
* return (
|
|
|
|
* <MyLoadingComponent
|
|
|
|
* componentView={componentView}
|
|
|
|
* loadingView={progressBar}
|
|
|
|
* style={styles.loadingComponent}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* },
|
|
|
|
* ```
|
|
|
|
*/
|
2017-09-19 06:45:19 +00:00
|
|
|
class ProgressBarAndroid extends ReactNative.NativeComponent {
|
|
|
|
static propTypes = {
|
2017-03-24 07:22:57 +00:00
|
|
|
...ViewPropTypes,
|
2017-09-19 06:45:19 +00:00
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
/**
|
|
|
|
* Style of the ProgressBar. One of:
|
|
|
|
*
|
|
|
|
* - Horizontal
|
2016-01-07 16:44:14 +00:00
|
|
|
* - Normal (default)
|
2015-09-14 14:35:58 +00:00
|
|
|
* - Small
|
|
|
|
* - Large
|
|
|
|
* - Inverse
|
|
|
|
* - SmallInverse
|
|
|
|
* - LargeInverse
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
styleAttr: PropTypes.oneOf(STYLE_ATTRIBUTES),
|
2017-10-18 23:50:41 +00:00
|
|
|
/**
|
|
|
|
* Whether to show the ProgressBar (true, the default) or hide it (false).
|
|
|
|
*/
|
|
|
|
animating: PropTypes.bool,
|
2015-11-06 20:07:54 +00:00
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
progress: PropTypes.number,
|
2015-11-06 10:33:32 +00:00
|
|
|
/**
|
|
|
|
* Color of the progress bar.
|
|
|
|
*/
|
2015-12-23 03:29:01 +00:00
|
|
|
color: ColorPropType,
|
2015-09-14 14:35:58 +00:00
|
|
|
/**
|
|
|
|
* Used to locate this view in end-to-end tests.
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
testID: PropTypes.string,
|
2017-09-19 06:45:19 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-09-19 06:45:19 +00:00
|
|
|
static defaultProps = {
|
|
|
|
styleAttr: 'Normal',
|
2017-10-18 23:50:41 +00:00
|
|
|
indeterminate: true,
|
|
|
|
animating: true,
|
2017-09-19 06:45:19 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-09-19 06:45:19 +00:00
|
|
|
render() {
|
2017-10-18 23:50:41 +00:00
|
|
|
return <AndroidProgressBar {...this.props} />;
|
2017-09-19 06:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-10-18 23:50:41 +00:00
|
|
|
const AndroidProgressBar = requireNativeComponent(
|
|
|
|
'AndroidProgressBar',
|
|
|
|
ProgressBarAndroid,
|
|
|
|
{
|
|
|
|
nativeOnly: {
|
|
|
|
animating: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
module.exports = ProgressBarAndroid;
|