Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 6ebdfae

Browse files
committed
code refactor
1 parent 3e1ab13 commit 6ebdfae

File tree

4 files changed

+59
-35
lines changed

4 files changed

+59
-35
lines changed

js/components/ListViewFooter.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Created by wangdi on 7/12/16.
3+
*/
4+
'use strict';
5+
6+
import React, {Component, PropTypes} from 'react';
7+
import {Text, View, StyleSheet, ActivityIndicator} from 'react-native';
8+
import theme from '../constants/theme';
9+
import px2dp from '../utils/px2dp';
10+
11+
export default class ListViewFooter extends Component{
12+
static propTypes = {
13+
isRenderFooter: PropTypes.bool,
14+
isFullData: PropTypes.bool,
15+
indicatorColor: PropTypes.string
16+
};
17+
18+
render(){
19+
if(this.props.isRenderFooter) {
20+
if (this.props.isFullData)
21+
return (
22+
<View style={styles.footer}>
23+
<Text style={{color: this.props.indicatorColor}}>已加载全部</Text>
24+
</View>
25+
);
26+
else
27+
return (
28+
<View style={styles.footer}>
29+
<ActivityIndicator
30+
color={this.props.indicatorColor}
31+
/>
32+
<Text style={{marginLeft: 10, color: this.props.indicatorColor}}>拼命获取中...</Text>
33+
</View>
34+
);
35+
}
36+
return null;
37+
}
38+
}
39+
40+
const styles = StyleSheet.create({
41+
footer: {
42+
flexDirection: 'row',
43+
width: theme.screenWidth,
44+
height: px2dp(60),
45+
alignItems: 'center',
46+
justifyContent: 'center',
47+
}
48+
});

js/components/ListViewForGirls.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {StyleSheet, View, Text, Image, ListView, Platform, ActivityIndicator, To
66
import {connect} from 'react-redux';
77
import theme from '../constants/theme';
88
import px2dp from '../utils/px2dp';
9+
import Footer from './ListViewFooter';
910

1011
class ListViewForGirls extends Component{
1112
constructor(props){
@@ -36,23 +37,10 @@ class ListViewForGirls extends Component{
3637
}
3738

3839
_renderFooter(){
39-
if(this.props.isRenderFooter) {
40-
if (this.props.isFullData)
41-
return (
42-
<View style={styles.footer}>
43-
<Text style={{color: this.props.tabIconColor}}>已加载全部</Text>
44-
</View>
45-
);
46-
else
47-
return (
48-
<View style={styles.footer}>
49-
<ActivityIndicator
50-
color={this.props.tabIconColor}
51-
/>
52-
<Text style={{marginLeft: 10, color: this.props.tabIconColor}}>拼命获取中...</Text>
53-
</View>
54-
);
55-
}
40+
const {isRenderFooter, tabIconColor, isFullData} = this.props;
41+
return(
42+
<Footer indicatorColor={tabIconColor} isFullData={isFullData} isRenderFooter={isRenderFooter}/>
43+
);
5644
}
5745

5846
_renderSeparator(sectionID, rowID, adjacentRowHighlighted){

js/components/ListViewWithInfo.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import theme from '../constants/theme';
1111
import px2dp from '../utils/px2dp';
1212
import WebViewPage from '../containers/WebViewPage';
1313
import getCorrectImageSizeUrl from '../utils/imageFactory';
14+
import Footer from './ListViewFooter';
1415

1516
class ListViewWithInfo extends Component{
1617
constructor(props){
@@ -42,23 +43,10 @@ class ListViewWithInfo extends Component{
4243
}
4344

4445
_renderFooter(){
45-
if(this.props.isRenderFooter) {
46-
if (this.props.isFullData)
47-
return (
48-
<View style={styles.footer}>
49-
<Text style={{color: this.props.tabIconColor}}>已加载全部</Text>
50-
</View>
51-
);
52-
else
53-
return (
54-
<View style={styles.footer}>
55-
<ActivityIndicator
56-
color={this.props.tabIconColor}
57-
/>
58-
<Text style={{marginLeft: 10, color: this.props.tabIconColor}}>拼命获取中...</Text>
59-
</View>
60-
);
61-
}
46+
const {isRenderFooter, tabIconColor, isFullData} = this.props;
47+
return(
48+
<Footer indicatorColor={tabIconColor} isFullData={isFullData} isRenderFooter={isRenderFooter}/>
49+
);
6250
}
6351

6452
_renderRow(rowData, sectionID, rowID, highlightRow){

js/containers/DiscoveryTab/GirlsPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'use strict';
66

77
import React, {Component} from 'react';
8-
import {StyleSheet, InteractionManager, View, Text, ScrollView, Image, ListView, ActivityIndicator} from 'react-native';
8+
import {StyleSheet, InteractionManager, View, Button, Text, ScrollView, Image, ListView, ActivityIndicator} from 'react-native';
99
import theme from '../../constants/theme';
1010
import NavigationBar from '../../components/NavigationBar';
1111
import BackPageComponent from '../../components/BackPageComponent';

0 commit comments

Comments
 (0)