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

Commit ee64e0c

Browse files
committed
code refactor
1 parent 63aad00 commit ee64e0c

File tree

2 files changed

+43
-58
lines changed

2 files changed

+43
-58
lines changed

js/component/Button.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ export default class Button extends Component{
1919
return (
2020
<TouchableNativeFeedback
2121
onPress={this.props.onPress}>
22-
<View style={{flex: 1, height: px2dp(45), backgroundColor: '#046ada', alignItems:'center', justifyContent:'center',
23-
borderRadius: 3}}>
24-
<Text style={styles.text}>{this.props.text}</Text>
25-
</View>
22+
{this._renderContent()}
2623
</TouchableNativeFeedback>
2724
);
2825
}else if(Platform.OS === 'ios'){
2926
return(
3027
<TouchableHighlight
3128
onPress={this.props.onPress}
3229
activeOpacity={theme.btnActiveOpacity}>
33-
<View style={{flex: 1, height: px2dp(45), backgroundColor: '#046ada', alignItems:'center', justifyContent:'center',
34-
borderRadius: 3}}>
35-
<Text style={styles.text}>{this.props.text}</Text>
36-
</View>
30+
{this._renderContent()}
3731
</TouchableHighlight>
3832
);
3933
}
4034
}
35+
36+
_renderContent(){
37+
return(
38+
<View style={{flex: 1, height: px2dp(45), backgroundColor: '#046ada', alignItems:'center', justifyContent:'center',
39+
borderRadius: 3}}>
40+
<Text style={styles.text}>{this.props.text}</Text>
41+
</View>
42+
);
43+
}
4144
}
4245

4346
const styles = StyleSheet.create({

js/component/HotPanel.js

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -77,62 +77,14 @@ export default class HotPanel extends Component{
7777
key={index}
7878
onPress={this._hotPanelCallback.bind(this, item)}
7979
activeOpacity={theme.btnActiveOpacity}>
80-
<View>
81-
<View style={styles.listItem}>
82-
<View style={{flex: 80, marginTop: px2dp(10)}}>
83-
<Text style={styles.content} numberOfLines={2}>{item.title}</Text>
84-
<View style={styles.infoBar}>
85-
<Icon name="heart" size={px2dp(13)} color={theme.grayColor}/>
86-
<Text style={styles.infoBarText}>{item.collectionCount}</Text>
87-
<Icon name="person" size={px2dp(12)} color={theme.grayColor}/>
88-
<Text style={styles.infoBarText}>{item.user.username}</Text>
89-
<Icon name="clock" size={px2dp(13)} color={theme.grayColor}/>
90-
<Text style={styles.infoBarText}>{item.time}</Text>
91-
</View>
92-
</View>
93-
<View style={{flex: 20, flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center'}}>
94-
{item.screenshot ?
95-
<Image source={{uri: item.screenshot.url}}
96-
style={styles.image}/>
97-
:
98-
<Image source={require('../image/user_article_no_data.png')}
99-
style={styles.image}/>
100-
}
101-
</View>
102-
</View>
103-
<View style={{height: 1/PixelRatio.get(), backgroundColor: '#f1f1f1'}}></View>
104-
</View>
80+
{this._renderContent(item, index)}
10581
</TouchableOpacity>
10682
)}else if(Platform.OS === 'android'){
10783
return(
10884
<TouchableNativeFeedback
10985
key={index}
11086
onPress={this._hotPanelCallback.bind(this, item)}>
111-
<View>
112-
<View style={styles.listItem}>
113-
<View style={{flex: 80, marginTop: px2dp(10)}}>
114-
<Text style={styles.content} numberOfLines={2}>{item.title}</Text>
115-
<View style={styles.infoBar}>
116-
<Icon name="heart" size={px2dp(13)} color={theme.grayColor}/>
117-
<Text style={styles.infoBarText}>{item.collectionCount}</Text>
118-
<Icon name="person" size={px2dp(12)} color={theme.grayColor}/>
119-
<Text style={styles.infoBarText}>{item.user.username}</Text>
120-
<Icon name="clock" size={px2dp(13)} color={theme.grayColor}/>
121-
<Text style={styles.infoBarText}>{item.time}</Text>
122-
</View>
123-
</View>
124-
<View style={{flex: 20, flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center'}}>
125-
{item.screenshot ?
126-
<Image source={{uri: item.screenshot.url}}
127-
style={styles.image}/>
128-
:
129-
<Image source={require('../image/user_article_no_data.png')}
130-
style={styles.image}/>
131-
}
132-
</View>
133-
</View>
134-
<View style={{height: 1/PixelRatio.get(), backgroundColor: '#f1f1f1'}}></View>
135-
</View>
87+
{this._renderContent(item, index)}
13688
</TouchableNativeFeedback>
13789
)}})
13890
}
@@ -144,6 +96,36 @@ export default class HotPanel extends Component{
14496
}
14597
}
14698

99+
_renderContent(item, index){
100+
return(
101+
<View>
102+
<View style={styles.listItem}>
103+
<View style={{flex: 80, marginTop: px2dp(10)}}>
104+
<Text style={styles.content} numberOfLines={2}>{item.title}</Text>
105+
<View style={styles.infoBar}>
106+
<Icon name="heart" size={px2dp(13)} color={theme.grayColor}/>
107+
<Text style={styles.infoBarText}>{item.collectionCount}</Text>
108+
<Icon name="person" size={px2dp(12)} color={theme.grayColor}/>
109+
<Text style={styles.infoBarText}>{item.user.username}</Text>
110+
<Icon name="clock" size={px2dp(13)} color={theme.grayColor}/>
111+
<Text style={styles.infoBarText}>{item.time}</Text>
112+
</View>
113+
</View>
114+
<View style={{flex: 20, flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center'}}>
115+
{item.screenshot ?
116+
<Image source={{uri: item.screenshot.url}}
117+
style={styles.image}/>
118+
:
119+
<Image source={require('../image/user_article_no_data.png')}
120+
style={styles.image}/>
121+
}
122+
</View>
123+
</View>
124+
<View style={{height: 1/PixelRatio.get(), backgroundColor: '#f1f1f1'}}></View>
125+
</View>
126+
);
127+
}
128+
147129
_closeBtCallback(){
148130
this.setState({isHotPanelShow: false});
149131
}

0 commit comments

Comments
 (0)