YH_RefreshingIndicator.js
3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImagesAsGif from '../components/ImagesAsGif';
import PropTypes from 'prop-types';
const {
isValidElement,
createElement,
} = React;
const {
View,
Text,
Image,
TouchableOpacity,
ActivityIndicator,
StyleSheet,
Dimensions,
} = ReactNative;
let {width, height} = Dimensions.get('window');
export default class YH_RefreshingIndicator extends React.Component {
static propTypes = {
activityIndicatorComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
stylesheet: PropTypes.object,
isTouching: PropTypes.bool,
isRefreshing: PropTypes.bool,
isWaitingForRelease: PropTypes.bool,
};
static defaultProps = {
activityIndicatorComponent: ActivityIndicator,
isTouching: false,
isRefreshing: false,
isWaitingForRelease: false,
};
constructor(props) {
super (props);
}
renderActivityIndicator(styles) {
var activityIndicator
if (this.props.isTouching && this.props.isWaitingForRelease) {
activityIndicator = <Image source={require('./images/Boy/refresh_000.png')}/>
} else if (this.props.isTouching && !this.props.isWaitingForRelease) {
activityIndicator = <Image source={require('./images/Boy/refresh_000.png')}/>
} else if (!this.props.isTouching && this.props.isWaitingForRelease) {
activityIndicator = <Image source={require('./images/Boy/refresh_000.png')}/>
} else if (this.props.isRefreshing) {
let images = [
require('./images/Boy/refresh_000.png'),
require('./images/Boy/refresh_001.png'),
require('./images/Boy/refresh_002.png'),
require('./images/Boy/refresh_003.png'),
require('./images/Boy/refresh_004.png'),
require('./images/Boy/refresh_005.png'),
require('./images/Boy/refresh_006.png'),
require('./images/Boy/refresh_007.png'),
require('./images/Boy/refresh_008.png'),
require('./images/Boy/refresh_009.png'),
require('./images/Boy/refresh_010.png'),
require('./images/Boy/refresh_011.png'),
require('./images/Boy/refresh_012.png'),
];
activityIndicator = <ImagesAsGif images={images} duration={100} />
// activityIndicator = <Image source={require('./images/Boy/loading.gif')} style={{width: 80, height: 20}}/>
}
if (activityIndicator) {
if (isValidElement(activityIndicator)) return activityIndicator
// is a component class, not an element
return createElement(activityIndicator, {style: styles.activityIndicator})
}
return null;
}
render() {
var styles = Object.assign({}, stylesheet, this.props.stylesheet)
return (
<View style={[styles.wrapper]}>
<View style={[styles.container, styles.loading, styles.content]}>
<View style={[styles.stack]}>
{this.renderActivityIndicator(styles)}
</View>
</View>
</View>
);
}
}
let stylesheet = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'flex-start',
flexDirection: 'row',
},
stack: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
},
wrapper: {
height: 45,
},
content: {
marginTop: 10,
height: 40,
},
});