Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 76c8bf0

Browse files
author
soliury
committed
abstract Nav Component
1 parent b939897 commit 76c8bf0

File tree

2 files changed

+130
-93
lines changed

2 files changed

+130
-93
lines changed

app/components/Nav.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
var React = require('react-native')
2+
3+
var window = require('../util/window')
4+
var { width, height } = window.get()
5+
6+
7+
var {
8+
Component,
9+
View,
10+
Text,
11+
StyleSheet,
12+
TouchableOpacity
13+
} = React
14+
15+
16+
class Nav extends Component {
17+
constructor(props) {
18+
super(props)
19+
}
20+
21+
22+
_renderNavContent() {
23+
var navs = this.props.navs || {}
24+
25+
return ['Left', 'Center', 'Right'].map((position)=> {
26+
var nav = navs[position]
27+
if (nav) {
28+
return (
29+
<TouchableOpacity
30+
onPress={nav.onPress}
31+
>
32+
<Text style={[styles.navItem,styles['nav'+position]]}>
33+
{nav.text}
34+
</Text>
35+
</TouchableOpacity>
36+
)
37+
}
38+
return (
39+
<View style={[styles.navItem,styles['nav'+position]]}>
40+
</View>
41+
)
42+
})
43+
}
44+
45+
46+
render() {
47+
return (
48+
<View
49+
ref={view=>this.nav=view}
50+
style={styles.nav}>
51+
52+
{this._renderNavContent()}
53+
54+
</View>
55+
)
56+
}
57+
}
58+
59+
var navHeight = 55
60+
61+
var styles = StyleSheet.create({
62+
nav: {
63+
height: navHeight,
64+
width: width,
65+
borderBottomColor: 'rgba(0,0,0,0.03)',
66+
borderBottomWidth: 1,
67+
flexDirection: 'row',
68+
justifyContent: 'center',
69+
alignItems: 'center'
70+
},
71+
navItem: {
72+
color: 'rgba(0,0,0,0.7)',
73+
fontSize: 16
74+
},
75+
navLeft: {
76+
textAlign: 'left',
77+
paddingLeft: 15,
78+
flex: 1
79+
},
80+
navRight: {
81+
textAlign: 'right',
82+
paddingRight: 15,
83+
flex: 1
84+
},
85+
navCenter: {
86+
textAlign: 'center',
87+
flex: 2
88+
}
89+
})
90+
91+
92+
module.exports = Nav

app/containers/Comments.js

Lines changed: 38 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var markdown = require("markdown").markdown
1313
var Return = require('../components/overlay/Return')
1414
var CommentHtml = require('../components/htmlRender/CommentHtml')
1515
var CommentUp = require('../components/comment/CommentUp')
16+
var Nav = require('../components/Nav')
1617

1718
var TopicService = require('../services/TopicService')
1819
var genColor = require('../util/genColor')
@@ -222,35 +223,13 @@ class Comments extends Component {
222223
}
223224

224225

225-
_onReturnPress() {
226-
this.props.router.pop()
227-
}
228-
229-
230-
_onReturnToTopic() {
231-
this.props.router.toTopic({
232-
topic: this.topic
233-
})
234-
}
235-
236-
237226
_onAuthorImgPress(authorName) {
238227
this.props.router.toUser({
239228
userName: authorName
240229
})
241230
}
242231

243232

244-
_onCommentTitlePress() {
245-
this._listView.setNativeProps({
246-
contentOffset: {
247-
x: 0,
248-
y: 0
249-
}
250-
})
251-
}
252-
253-
254233
renderRow(comment, sectionID, rowID, highlightRow) {
255234
var authorName = comment.author.loginname
256235
var domain = config.domain
@@ -431,47 +410,48 @@ class Comments extends Component {
431410

432411
render() {
433412
var count = this.state.ds.getRowCount()
434-
var returnToTopic = (
435-
<TouchableHighlight
436-
onPress={this._onReturnToTopic.bind(this)}
437-
underlayColor='rgba(0,0,0,0.1)'
438-
style={styles.navToTopic}>
439-
<Text style={styles.navReturnText}>
440-
正文
441-
</Text>
442-
</TouchableHighlight>
443-
)
444413

445-
return (
446-
<View style={styles.container}>
447-
<View
448-
ref={view=>this.nav=view}
449-
style={styles.nav}>
450-
<TouchableHighlight
451-
onPress={this._onReturnPress.bind(this)}
452-
underlayColor='rgba(0,0,0,0.1)'
453-
style={styles.navReturn}>
454-
<Text style={styles.navReturnText}>
455-
返回
456-
</Text>
457-
</TouchableHighlight>
414+
var router = this.props.router
458415

459-
<TouchableOpacity
460-
onPress={this._onCommentTitlePress.bind(this)}
461-
style={styles.navTitle}>
462-
<Text style={styles.titleText}>
463-
评论
464-
<Text style={styles.countText}>
465-
{' ' + count.toString()}
466-
</Text>
467-
</Text>
468-
</TouchableOpacity>
416+
var navs = {
417+
Left: {
418+
text: '返回',
419+
onPress: ()=> {
420+
router.pop()
421+
}
422+
},
423+
Center: {
424+
text: '评论 ' + count,
425+
onPress: ()=> {
426+
this._listView.setNativeProps({
427+
contentOffset: {
428+
x: 0,
429+
y: 0
430+
}
431+
})
432+
}
433+
}
434+
}
469435

470-
{
471-
(this.state.didFocus && this.props.reply && this.state.isLoaded) ? returnToTopic : null
436+
if (this.state.didFocus && this.props.reply && this.state.isLoaded) {
437+
navs = {
438+
...navs,
439+
Right: {
440+
text: '正文',
441+
onPress: ()=> {
442+
router.toTopic({
443+
topic: this.topic
444+
})
472445
}
446+
}
447+
}
448+
}
473449

474-
</View>
450+
return (
451+
<View style={styles.container}>
452+
<Nav
453+
navs={navs}
454+
></Nav>
475455

476456
<View
477457
ref={view=>this.commentsView=view}
@@ -507,47 +487,12 @@ var styles = StyleSheet.create({
507487
backgroundColor: 'white',
508488
height: height
509489
},
510-
nav: {
511-
height: navHeight,
512-
width: width,
513-
borderBottomColor: 'rgba(0,0,0,0.03)',
514-
borderBottomWidth: 1,
515-
flexDirection: 'row',
516-
justifyContent: 'center',
517-
alignItems: 'center'
518-
},
519-
520-
navReturn: {
521-
height: navHeight,
522-
position: 'absolute',
523-
left: 0,
524-
top: 0,
525-
paddingLeft: 15,
526-
paddingRight: 15
527-
},
528-
529-
navToTopic: {
530-
height: navHeight,
531-
position: 'absolute',
532-
right: 0,
533-
top: 0,
534-
paddingLeft: 15,
535-
paddingRight: 15
536-
},
537-
navReturnText: {
538-
lineHeight: navHeight - 20,
539-
fontSize: 16
540-
},
541490

542491
titleText: {
543492
color: 'rgba(0,0,0,0.7)',
544493
fontSize: 16
545494
},
546495

547-
countText: {
548-
color: 'rgba(0,0,0,0.45)'
549-
},
550-
551496
comments: {
552497
//marginTop: 20,
553498
width: width,

0 commit comments

Comments
 (0)