YRActivityIndicator.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import { Loading, EasyLoading } from './YRLoading';
  3. import {
  4. AppRegistry,
  5. StyleSheet,
  6. Text,
  7. View,
  8. ActivityIndicator,
  9. TouchableOpacity
  10. } from 'react-native';
  11. class YRActivityIndicator extends React.Component{
  12. constructor(props){
  13. super(props);
  14. this.state = {// 初始设为显示加载动画
  15. animating: true,
  16. };
  17. }
  18. showOrHide() {
  19. EasyLoading.show('Loading...');
  20. // setTimeout(()=>{
  21. // EasyLoading.dismis();
  22. // },11000);
  23. if (this.state.animating) {
  24. this.setState({
  25. animating: false
  26. });
  27. } else {
  28. this.setState({
  29. animating: true
  30. });
  31. }
  32. }
  33. dissLoading() {
  34. EasyLoading.dismis()
  35. }
  36. componentDidMount() {
  37. }
  38. render(){
  39. return ( <View style={styles.container}>
  40. {/* 切换显示或隐藏的按钮 */}
  41. <TouchableOpacity underlayColor="#fff" style={styles.btn} onPress={
  42. this.showOrHide.bind(this)}>
  43. <Text style={{color:'#fff', fontSize: 20}}>显示/隐藏</Text>
  44. </TouchableOpacity>
  45. <TouchableOpacity underlayColor="#fff" style={styles.btn} onPress={
  46. this.dissLoading.bind(this)}>
  47. <Text style={{color:'#fff', fontSize: 20}}>关闭</Text>
  48. </TouchableOpacity>
  49. {/* 小号的指示器 */}
  50. <ActivityIndicator
  51. animating={this.state.animating}
  52. size="small" />
  53. {/* 大号的指示器 */}
  54. <ActivityIndicator
  55. animating={this.state.animating}
  56. style={[styles.centering, {height: 80}]}
  57. size="large" />
  58. <Loading />
  59. </View>)
  60. }
  61. }
  62. const styles = StyleSheet.create({
  63. container: {
  64. flex: 1,
  65. justifyContent: 'center',
  66. alignItems: 'center',
  67. backgroundColor: '#F5FCFF',
  68. },
  69. centering: {
  70. alignItems: 'center',
  71. justifyContent: 'center',
  72. padding: 8,
  73. },
  74. btn:{
  75. marginTop:10,
  76. width:150,
  77. height:35,
  78. backgroundColor:'#3BC1FF',
  79. justifyContent:'center',
  80. alignItems:'center',
  81. borderRadius:4,
  82. },
  83. });
  84. export default YRActivityIndicator;