2015-01-30 01:10:49 +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-09 15:32:04 +00:00
|
|
|
* @flow strict-local
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-01-30 01:10:49 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
import React, {Component} from 'react';
|
|
|
|
import {ActivityIndicator, StyleSheet, View} from 'react-native';
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-08-03 00:06:37 +00:00
|
|
|
/**
|
|
|
|
* Optional Flowtype state and timer types definition
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
type State = {animating: boolean};
|
2016-08-03 00:06:37 +00:00
|
|
|
type Timer = number;
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class ToggleAnimatingActivityIndicator extends Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
State,
|
|
|
|
> {
|
2016-08-03 00:06:37 +00:00
|
|
|
_timer: Timer;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-08-03 00:06:37 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2015-01-30 01:10:49 +00:00
|
|
|
animating: true,
|
|
|
|
};
|
2016-08-03 00:06:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.setToggleTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2018-01-08 20:45:38 +00:00
|
|
|
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
|
|
|
|
* error found when Flow v0.63 was deployed. To see the error delete this
|
|
|
|
* comment and run Flow. */
|
2016-08-03 00:06:37 +00:00
|
|
|
clearTimeout(this._timer);
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
setToggleTimeout() {
|
2018-01-08 20:45:38 +00:00
|
|
|
/* $FlowFixMe(>=0.63.0 site=react_native_fb) This comment suppresses an
|
|
|
|
* error found when Flow v0.63 was deployed. To see the error delete this
|
|
|
|
* comment and run Flow. */
|
2016-08-03 00:06:37 +00:00
|
|
|
this._timer = setTimeout(() => {
|
2016-05-26 20:46:58 +00:00
|
|
|
this.setState({animating: !this.state.animating});
|
|
|
|
this.setToggleTimeout();
|
|
|
|
}, 2000);
|
2016-08-03 00:06:37 +00:00
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
2015-01-30 01:10:49 +00:00
|
|
|
animating={this.state.animating}
|
|
|
|
style={[styles.centering, {height: 80}]}
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2015-01-30 01:10:49 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-08-03 00:06:37 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 22:23:40 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-01-30 01:10:49 +00:00
|
|
|
exports.framework = 'React';
|
2016-05-26 20:46:58 +00:00
|
|
|
exports.title = '<ActivityIndicator>';
|
2015-01-30 01:10:49 +00:00
|
|
|
exports.description = 'Animated loading indicators.';
|
|
|
|
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Default (small, white)',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering, styles.gray]}
|
2015-01-30 01:10:49 +00:00
|
|
|
color="white"
|
2016-05-26 20:46:58 +00:00
|
|
|
/>
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Gray',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<ActivityIndicator style={[styles.centering]} />
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering, {backgroundColor: '#eeeeee'}]}
|
2015-01-30 01:10:49 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Custom colors',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator color="#0000ff" />
|
|
|
|
<ActivityIndicator color="#aa00aa" />
|
|
|
|
<ActivityIndicator color="#aa3300" />
|
|
|
|
<ActivityIndicator color="#00aa00" />
|
2015-01-30 01:10:49 +00:00
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Large',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering, styles.gray]}
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2016-07-28 22:14:59 +00:00
|
|
|
color="white"
|
2015-01-30 01:10:49 +00:00
|
|
|
/>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Large, custom colors',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<ActivityIndicator size="large" color="#0000ff" />
|
|
|
|
<ActivityIndicator size="large" color="#aa00aa" />
|
|
|
|
<ActivityIndicator size="large" color="#aa3300" />
|
|
|
|
<ActivityIndicator size="large" color="#00aa00" />
|
2015-01-30 01:10:49 +00:00
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Start/stop',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-02-19 01:51:14 +00:00
|
|
|
return <ToggleAnimatingActivityIndicator />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
2016-05-26 20:46:58 +00:00
|
|
|
{
|
|
|
|
title: 'Custom size',
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering, {transform: [{scale: 1.5}]}]}
|
|
|
|
size="large"
|
|
|
|
/>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-05-26 20:46:58 +00:00
|
|
|
},
|
2016-07-28 22:14:59 +00:00
|
|
|
{
|
|
|
|
platform: 'android',
|
|
|
|
title: 'Custom size (size: 75)',
|
|
|
|
render() {
|
2018-05-11 20:32:37 +00:00
|
|
|
return <ActivityIndicator style={styles.centering} size={75} />;
|
|
|
|
},
|
2016-07-28 22:14:59 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
];
|
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-01-30 01:10:49 +00:00
|
|
|
centering: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2016-05-26 20:46:58 +00:00
|
|
|
padding: 8,
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
gray: {
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
},
|
|
|
|
horizontal: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-around',
|
2016-05-26 20:46:58 +00:00
|
|
|
padding: 8,
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
|
|
|
});
|