Skip to content

Commit

Permalink
fix render user header continuously
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Sep 14, 2018
1 parent 0748566 commit c6a908c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
34 changes: 18 additions & 16 deletions app/components/IssueDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class IssueDetailPage extends Component {
this._getBottomItem = this._getBottomItem.bind(this);
this._getOptionItem = this._getOptionItem.bind(this);
this._refresh = this._refresh.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this._loadMore = this._loadMore.bind(this);
this.sendIssueComment = this.sendIssueComment.bind(this);
this.editIssue = this.editIssue.bind(this);
Expand Down Expand Up @@ -395,24 +396,27 @@ class IssueDetailPage extends Component {
return owner ? ownerAction : copy;
}

_renderHeader() {
let {issue} = this.state;
return <IssueHead
actionTime={issue.created_at}
actionUser={issue.user.login}
actionUserPic={issue.user.avatar_url}
closed_by={issue.closed_by}
locked={issue.locked}
issueComment={issue.title}
issueDesHtml={issue.body_html ? issue.body_html : ""}
commentCount={issue.comments + ""}
state={issue.state}
issueDes={(issue.body) ? ((I18n('issueInfo') + ": \n" + issue.body)) : ''}
issueTag={"#" + issue.number}/>;
}

render() {
let {issue} = this.state;
let bottomBar = (issue) ?
<CommonBottomBar dataList={this._getBottomItem()}/> :
<View/>;
let header =
<IssueHead
actionTime={issue.created_at}
actionUser={issue.user.login}
actionUserPic={issue.user.avatar_url}
closed_by={issue.closed_by}
locked={issue.locked}
issueComment={issue.title}
issueDesHtml={issue.body_html ? issue.body_html : ""}
commentCount={issue.comments + ""}
state={issue.state}
issueDes={(issue.body) ? ((I18n('issueInfo') + ": \n" + issue.body)) : ''}
issueTag={"#" + issue.number}/>;
return (
<View style={styles.mainBox}>
<StatusBar hidden={false} backgroundColor={'transparent'} translucent barStyle={'light-content'}/>
Expand All @@ -424,9 +428,7 @@ class IssueDetailPage extends Component {
renderRow={(rowData, index) =>
this._renderRow(rowData, index)
}
renderHeader={() => {
return header
}}
renderHeader={this._renderHeader()}
refresh={this._refresh}
loadMore={this._loadMore}
dataSource={this.state.dataSource}
Expand Down
14 changes: 8 additions & 6 deletions app/components/PushDetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class PushDetailPage extends Component {
super(props);
this._refresh = this._refresh.bind(this);
this._loadMore = this._loadMore.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this.page = 2;
this.state = {
dataSource: [],
Expand Down Expand Up @@ -113,8 +114,7 @@ class PushDetailPage extends Component {

}


render() {
_renderHeader() {
let {pushDetail} = this.state;
let name = "";
let pic = "";
Expand All @@ -128,7 +128,7 @@ class PushDetailPage extends Component {
pic = pushDetail.committer.avatar_url;
}
}
let header = (pushDetail) ?
return (pushDetail) ?
<PushDetailHeader
actionUser={name}
actionUserPic={pic}
Expand All @@ -137,6 +137,10 @@ class PushDetailPage extends Component {
editCount={pushDetail.files.length + ""}
addCount={pushDetail.stats.additions + ""}
deleteCount={pushDetail.stats.deletions + ""}/> : <View/>;

}

render() {
return (
<View style={styles.mainBox}>
<StatusBar hidden={false} backgroundColor={'transparent'} translucent barStyle={'light-content'}/>
Expand All @@ -148,9 +152,7 @@ class PushDetailPage extends Component {
renderRow={(rowData, index) =>
this._renderRow(rowData)
}
renderHeader={() => {
return header
}}
renderHeader={this._renderHeader()}
refresh={this._refresh}
loadMore={this._loadMore}
dataSource={this.state.dataSource}
Expand Down
16 changes: 9 additions & 7 deletions app/components/RepositoryDetailActivityPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RepositoryDetailActivityPage extends Component {
this._refresh = this._refresh.bind(this);
this._loadMore = this._loadMore.bind(this);
this._renderRow = this._renderRow.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this._getBottomItem = this._getBottomItem.bind(this);
this.page = 2;
this.state = {
Expand Down Expand Up @@ -272,15 +273,13 @@ class RepositoryDetailActivityPage extends Component {
},]
}

render() {
_renderHeader() {
let {
forks_count, fork, open_issues_count, size, watchers_count, owner,
subscribers_count, description, language, created_at, pushed_at, parent,
topics, license, all_issues_count, closed_issues_count
} = this.props.dataDetail;
let data = this.state.select === 0 ? this.state.dataSource : this.state.dataSourceCommits;
let header =
<View>
return <View>
<RepositoryHeader
ownerName={this.props.ownerName}
ownerPic={owner ? owner.avatar_url : ""}
Expand Down Expand Up @@ -310,6 +309,11 @@ class RepositoryDetailActivityPage extends Component {
}}
dataList={this._getBottomItem()}/>
</View>;
}

render() {
let data = this.state.select === 0 ? this.state.dataSource : this.state.dataSourceCommits;


if (this.state.select === 2) {
data = [];
Expand All @@ -326,9 +330,7 @@ class RepositoryDetailActivityPage extends Component {
renderRow={(rowData, index) =>
this._renderRow(rowData)
}
renderHeader={() => {
return header
}}
renderHeader={this._renderHeader()}
refresh={this._refresh}
loadMore={this._loadMore}
dataSource={data}
Expand Down
13 changes: 7 additions & 6 deletions app/components/RepositoryDetailFilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RepositoryDetailFilePage extends Component {
this._loadMore = this._loadMore.bind(this);
this._renderHeaderRow = this._renderHeaderRow.bind(this);
this._renderRow = this._renderRow.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this.state = {
dataSource: [],
headerList: ["."],
Expand Down Expand Up @@ -225,10 +226,9 @@ class RepositoryDetailFilePage extends Component {
this._refresh("")
}

render() {
_renderHeader() {
let headerList = this.dsHeader.cloneWithRows(this.state.headerList);
let header =
<View style={[{height: 40, flex: 1, marginHorizontal: Constant.normalMarginEdge}]}>
return <View style={[{height: 40, flex: 1, marginHorizontal: Constant.normalMarginEdge}]}>
<ListView
renderRow={(rowData, sectionID, rowID, highlightRow) =>
this._renderHeaderRow(rowData, sectionID, rowID, highlightRow)
Expand All @@ -243,6 +243,9 @@ class RepositoryDetailFilePage extends Component {
dataSource={headerList}
/>
</View>;
}

render() {
return (
<View style={styles.mainBox}>
<StatusBar hidden={false} backgroundColor={'transparent'} translucent barStyle={'light-content'}/>
Expand All @@ -252,9 +255,7 @@ class RepositoryDetailFilePage extends Component {
renderRow={(rowData, index) =>
this._renderRow(rowData)
}
renderHeader={() => {
return header
}}
renderHeader={this._renderHeader()}
refresh={this._refresh}
loadMore={this._loadMore}
dataSource={this.state.dataSource}
Expand Down
28 changes: 15 additions & 13 deletions app/components/widget/PullLoadMoreListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PullLoadMoreListView extends Component {
this._renderFooter = this._renderFooter.bind(this);
this._refresh = this._refresh.bind(this);
this._loadMore = this._loadMore.bind(this);
this._renderEmpty = this._renderEmpty.bind(this);
//设置state
this.state = {
isRefresh: false,
Expand Down Expand Up @@ -99,16 +100,8 @@ class PullLoadMoreListView extends Component {
this.props.loadMore && this.props.loadMore();
}

render() {
let refreshProps = {
refreshing: this.state.isRefresh,
onRefresh: this._refresh,
tintColor: Constant.primaryColor,
title: I18n('refreshing'),
colors: [Constant.primaryColor, Constant.primaryLightColor],
};

let emptyView = (!this.props.hasOwnProperty("renderHeader")) ?
_renderEmpty() {
return (!this.props.hasOwnProperty("renderHeader")) ?
<View style={[styles.centered, {
flex: 1,
height: this.state.listHeight
Expand All @@ -126,13 +119,22 @@ class PullLoadMoreListView extends Component {
</Text>
</TouchableOpacity>
</View> : <View/>;
}

render() {
let refreshProps = {
refreshing: this.state.isRefresh,
onRefresh: this._refresh,
tintColor: Constant.primaryColor,
title: I18n('refreshing'),
colors: [Constant.primaryColor, Constant.primaryLightColor],
};

return (
<FlatList
style={{flex: 1}}
ref="list"
ListEmptyComponent={
() => emptyView
}
ListEmptyComponent={this._renderEmpty()}
removeClippedSubviews={true}
{...refreshProps}
onLayout={e => this.setState({listHeight: e.nativeEvent.layout.height})}
Expand Down

0 comments on commit c6a908c

Please sign in to comment.