react-native/Examples/UIExplorer/js/ActivityIndicatorExample.js

181 lines
4.0 KiB
JavaScript
Raw Normal View History

2015-01-30 01:10:49 +00:00
/**
* Copyright (c) 2013-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.
*
2015-03-26 18:24:15 +00:00
* The examples provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
2015-03-26 18:24:15 +00:00
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* @flow
2015-01-30 01:10:49 +00:00
*/
'use strict';
const React = require('react');
const ReactNative = require('react-native');
const {
ActivityIndicator,
2015-01-30 01:10:49 +00:00
StyleSheet,
View,
} = ReactNative;
const TimerMixin = require('react-timer-mixin');
2015-01-30 01:10:49 +00:00
const ToggleAnimatingActivityIndicator = React.createClass({
2015-01-30 01:10:49 +00:00
mixins: [TimerMixin],
getInitialState() {
2015-01-30 01:10:49 +00:00
return {
animating: true,
};
},
setToggleTimeout() {
this.setTimeout(() => {
this.setState({animating: !this.state.animating});
this.setToggleTimeout();
}, 2000);
2015-01-30 01:10:49 +00:00
},
componentDidMount() {
2015-01-30 01:10:49 +00:00
this.setToggleTimeout();
},
render() {
2015-01-30 01:10:49 +00:00
return (
<ActivityIndicator
2015-01-30 01:10:49 +00:00
animating={this.state.animating}
style={[styles.centering, {height: 80}]}
size="large"
2015-01-30 01:10:49 +00:00
/>
);
}
});
exports.displayName = (undefined: ?string);
2015-01-30 01:10:49 +00:00
exports.framework = 'React';
exports.title = '<ActivityIndicator>';
2015-01-30 01:10:49 +00:00
exports.description = 'Animated loading indicators.';
exports.examples = [
{
title: 'Default (small, white)',
render() {
2015-01-30 01:10:49 +00:00
return (
<ActivityIndicator
style={[styles.centering, styles.gray]}
2015-01-30 01:10:49 +00:00
color="white"
/>
2015-01-30 01:10:49 +00:00
);
}
},
{
title: 'Gray',
render() {
2015-01-30 01:10:49 +00:00
return (
<View>
<ActivityIndicator
style={[styles.centering]}
2015-01-30 01:10:49 +00:00
/>
<ActivityIndicator
style={[styles.centering, {backgroundColor: '#eeeeee'}]}
2015-01-30 01:10:49 +00:00
/>
</View>
);
}
},
{
title: 'Custom colors',
render() {
2015-01-30 01:10:49 +00:00
return (
<View style={styles.horizontal}>
<ActivityIndicator color="#0000ff" />
<ActivityIndicator color="#aa00aa" />
<ActivityIndicator color="#aa3300" />
<ActivityIndicator color="#00aa00" />
2015-01-30 01:10:49 +00:00
</View>
);
}
},
{
title: 'Large',
render() {
2015-01-30 01:10:49 +00:00
return (
<ActivityIndicator
style={[styles.centering, styles.gray]}
2015-01-30 01:10:49 +00:00
color="white"
size="large"
2015-01-30 01:10:49 +00:00
/>
);
}
},
{
title: 'Large, custom colors',
render() {
2015-01-30 01:10:49 +00:00
return (
<View style={styles.horizontal}>
<ActivityIndicator
size="large"
2015-01-30 01:10:49 +00:00
color="#0000ff"
/>
<ActivityIndicator
size="large"
2015-01-30 01:10:49 +00:00
color="#aa00aa"
/>
<ActivityIndicator
size="large"
2015-01-30 01:10:49 +00:00
color="#aa3300"
/>
<ActivityIndicator
size="large"
2015-01-30 01:10:49 +00:00
color="#00aa00"
/>
</View>
);
}
},
{
title: 'Start/stop',
render() {
return <ToggleAnimatingActivityIndicator />;
2015-01-30 01:10:49 +00:00
}
},
{
title: 'Custom size',
render() {
return (
<ActivityIndicator
style={[styles.centering, {transform: [{scale: 1.5}]}]}
size="large"
/>
);
}
},
2015-01-30 01:10:49 +00:00
];
const styles = StyleSheet.create({
2015-01-30 01:10:49 +00:00
centering: {
alignItems: 'center',
justifyContent: 'center',
padding: 8,
2015-01-30 01:10:49 +00:00
},
gray: {
backgroundColor: '#cccccc',
},
horizontal: {
flexDirection: 'row',
justifyContent: 'space-around',
padding: 8,
2015-01-30 01:10:49 +00:00
},
});