react-native/RNTester/js/ProgressViewIOSExample.js

104 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-06-03 09:49:22 -07:00
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
2015-06-03 09:49:22 -07:00
* @flow
*/
2015-06-03 09:49:22 -07:00
'use strict';
const React = require('react');
const ReactNative = require('react-native');
const {ProgressViewIOS, StyleSheet, View} = ReactNative;
2015-06-03 09:49:22 -07:00
type Props = {||};
type State = {|
progress: number,
|};
2015-06-03 09:49:22 -07:00
class ProgressViewExample extends React.Component<Props, State> {
_rafId: ?AnimationFrameID = null;
state = {
progress: 0,
};
2015-06-03 09:49:22 -07:00
componentDidMount() {
this.updateProgress();
}
2015-06-03 09:49:22 -07:00
componentWillUnmount() {
if (this._rafId != null) {
cancelAnimationFrame(this._rafId);
}
}
updateProgress = () => {
2015-06-03 09:49:22 -07:00
var progress = this.state.progress + 0.01;
this.setState({progress});
this._rafId = requestAnimationFrame(() => this.updateProgress());
};
2015-06-03 09:49:22 -07:00
getProgress = offset => {
2015-06-03 09:49:22 -07:00
var progress = this.state.progress + offset;
return Math.sin(progress % Math.PI) % 1;
};
2015-06-03 09:49:22 -07:00
render() {
return (
<View style={styles.container}>
<ProgressViewIOS
style={styles.progressView}
progress={this.getProgress(0)}
/>
<ProgressViewIOS
style={styles.progressView}
progressTintColor="purple"
progress={this.getProgress(0.2)}
/>
<ProgressViewIOS
style={styles.progressView}
progressTintColor="red"
progress={this.getProgress(0.4)}
/>
<ProgressViewIOS
style={styles.progressView}
progressTintColor="orange"
progress={this.getProgress(0.6)}
/>
<ProgressViewIOS
style={styles.progressView}
progressTintColor="yellow"
progress={this.getProgress(0.8)}
/>
2015-06-03 09:49:22 -07:00
</View>
);
}
}
2015-06-03 09:49:22 -07:00
exports.displayName = (undefined: ?string);
2015-06-03 09:49:22 -07:00
exports.framework = 'React';
exports.title = 'ProgressViewIOS';
exports.description = 'ProgressViewIOS';
exports.examples = [
{
title: 'ProgressViewIOS',
render() {
return <ProgressViewExample />;
},
},
];
2015-06-03 09:49:22 -07:00
var styles = StyleSheet.create({
container: {
marginTop: -20,
backgroundColor: 'transparent',
},
progressView: {
marginTop: 20,
},
2015-06-03 09:49:22 -07:00
});