2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule ActivityIndicatorExample
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-08-03 00:06: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
|
|
|
|
*/
|
|
|
|
type State = { animating: boolean; };
|
|
|
|
type Timer = number;
|
|
|
|
|
|
|
|
class ToggleAnimatingActivityIndicator extends Component {
|
|
|
|
/**
|
|
|
|
* Optional Flowtype state and timer types
|
|
|
|
*/
|
|
|
|
state: State;
|
|
|
|
_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() {
|
|
|
|
clearTimeout(this._timer);
|
|
|
|
}
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-05-26 20:46:58 +00:00
|
|
|
setToggleTimeout() {
|
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-01-30 01:10:49 +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
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Gray',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-01-30 01:10:49 +00:00
|
|
|
return (
|
|
|
|
<View>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering]}
|
2015-01-30 01:10:49 +00:00
|
|
|
/>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
|
|
|
style={[styles.centering, {backgroundColor: '#eeeeee'}]}
|
2015-01-30 01:10:49 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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}>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2015-01-30 01:10:49 +00:00
|
|
|
color="#0000ff"
|
|
|
|
/>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2015-01-30 01:10:49 +00:00
|
|
|
color="#aa00aa"
|
|
|
|
/>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2015-01-30 01:10:49 +00:00
|
|
|
color="#aa3300"
|
|
|
|
/>
|
2016-05-26 20:46:58 +00:00
|
|
|
<ActivityIndicator
|
2015-03-05 05:06:49 +00:00
|
|
|
size="large"
|
2015-01-30 01:10:49 +00:00
|
|
|
color="#00aa00"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Start/stop',
|
2016-05-26 20:46:58 +00:00
|
|
|
render() {
|
2015-02-19 01:51:14 +00:00
|
|
|
return <ToggleAnimatingActivityIndicator />;
|
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"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2016-07-28 22:14:59 +00:00
|
|
|
{
|
|
|
|
platform: 'android',
|
|
|
|
title: 'Custom size (size: 75)',
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ActivityIndicator
|
|
|
|
style={styles.centering}
|
|
|
|
size={75}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
];
|
|
|
|
|
2016-07-28 22:14:59 +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
|
|
|
},
|
|
|
|
});
|