2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
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-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2018-08-08 17:39:16 +00:00
|
|
|
* @flow
|
2015-09-14 14:35:58 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-30 19:55:17 +00:00
|
|
|
const ProgressBar = require('ProgressBarAndroid');
|
|
|
|
const React = require('React');
|
|
|
|
const RNTesterBlock = require('RNTesterBlock');
|
|
|
|
const RNTesterPage = require('RNTesterPage');
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2018-11-02 19:10:49 +00:00
|
|
|
import type {ProgressBarAndroidProps} from 'ProgressBarAndroid';
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2018-11-02 19:10:49 +00:00
|
|
|
type MovingBarProps = $ReadOnly<{|
|
|
|
|
...$Diff<
|
|
|
|
ProgressBarAndroidProps,
|
|
|
|
{
|
|
|
|
progress: ?number,
|
|
|
|
},
|
|
|
|
>,
|
|
|
|
indeterminate: false,
|
|
|
|
|}>;
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2018-11-02 19:10:49 +00:00
|
|
|
type MovingBarState = {
|
|
|
|
progress: number,
|
|
|
|
};
|
|
|
|
|
|
|
|
class MovingBar extends React.Component<MovingBarProps, MovingBarState> {
|
|
|
|
_intervalID: ?IntervalID = null;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
progress: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-10-05 17:43:13 +00:00
|
|
|
this._intervalID = setInterval(() => {
|
2018-10-30 19:55:17 +00:00
|
|
|
const progress = (this.state.progress + 0.02) % 1;
|
2018-11-02 19:10:49 +00:00
|
|
|
this.setState({progress});
|
2018-05-11 20:32:37 +00:00
|
|
|
}, 50);
|
2018-11-02 19:10:49 +00:00
|
|
|
}
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2018-11-02 19:10:49 +00:00
|
|
|
componentWillUnmount() {
|
2018-10-05 17:43:13 +00:00
|
|
|
if (this._intervalID != null) {
|
|
|
|
clearInterval(this._intervalID);
|
|
|
|
}
|
2018-11-02 19:10:49 +00:00
|
|
|
}
|
2018-10-05 17:43:13 +00:00
|
|
|
|
2018-11-02 19:10:49 +00:00
|
|
|
render() {
|
2015-11-06 20:07:54 +00:00
|
|
|
return <ProgressBar progress={this.state.progress} {...this.props} />;
|
2018-11-02 19:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ProgressBarAndroidExample extends React.Component<{}> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterPage title="ProgressBar Examples">
|
|
|
|
<RNTesterBlock title="Horizontal Indeterminate ProgressBar">
|
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. */}
|
2015-11-06 20:07:54 +00:00
|
|
|
<ProgressBar styleAttr="Horizontal" />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Horizontal ProgressBar">
|
2015-11-06 20:07:54 +00:00
|
|
|
<MovingBar styleAttr="Horizontal" indeterminate={false} />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Horizontal Black Indeterminate ProgressBar">
|
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. */}
|
2015-11-06 20:07:54 +00:00
|
|
|
<ProgressBar styleAttr="Horizontal" color="black" />
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
2015-11-06 20:07:54 +00:00
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
<RNTesterBlock title="Horizontal Blue ProgressBar">
|
2018-05-11 20:32:37 +00:00
|
|
|
<MovingBar
|
|
|
|
styleAttr="Horizontal"
|
|
|
|
indeterminate={false}
|
|
|
|
color="blue"
|
|
|
|
/>
|
2017-05-06 03:50:47 +00:00
|
|
|
</RNTesterBlock>
|
|
|
|
</RNTesterPage>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2018-12-31 16:26:00 +00:00
|
|
|
exports.title = '<ProgressBarAndroid>';
|
|
|
|
exports.description = 'Horizontal bar to show the progress of some operation.';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Simple progress bar',
|
|
|
|
render: function(): React.Element<typeof ProgressBarAndroidExample> {
|
|
|
|
return <ProgressBarAndroidExample />;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|