...
|
...
|
@@ -29,6 +29,7 @@ const { |
|
|
|
|
|
let {width, height} = Dimensions.get('window');
|
|
|
let bannerHeight = Math.ceil((363 / 750) * width);
|
|
|
let sectionBarHeight = 41;
|
|
|
|
|
|
export default class Section extends React.Component {
|
|
|
|
...
|
...
|
@@ -137,13 +138,14 @@ export default class Section extends React.Component { |
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
this._renderSeparator = this._renderSeparator.bind(this);
|
|
|
this._updateScrollValue = this._updateScrollValue.bind(this);
|
|
|
this._updateScrollableTableViewHeight = this._updateScrollableTableViewHeight.bind(this);
|
|
|
this._getCurrentPageHeight = this._getCurrentPageHeight.bind(this);
|
|
|
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
|
|
|
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
|
|
|
});
|
|
|
|
|
|
this.initialPageHeight = height - bannerHeight - sectionBarHeight;
|
|
|
this.currentPage = 0;
|
|
|
this.tabs = ['最新', '热门'];
|
|
|
|
...
|
...
|
@@ -196,13 +198,11 @@ export default class Section extends React.Component { |
|
|
ref={(c) => {
|
|
|
this.scrollableTabView = c;
|
|
|
}}
|
|
|
style={{height: this.state.scrollableTabViewHeight}}
|
|
|
renderTabBar={false}
|
|
|
initialPage={this.currentPage}
|
|
|
onScroll={this._updateScrollValue}
|
|
|
onChangeTab={(tab) => {
|
|
|
this._updateScrollableTableViewHeight(tab.i, true);
|
|
|
}}
|
|
|
getCurrentPageHeight={this._getCurrentPageHeight}
|
|
|
prerenderingSiblingsNumber={Infinity}
|
|
|
>
|
|
|
<SectionList
|
|
|
ref={(c) => {
|
...
|
...
|
@@ -214,9 +214,7 @@ export default class Section extends React.Component { |
|
|
onPressSectionTag={this.props.onPressSectionTag}
|
|
|
onPressComment={this.props.onPressComment}
|
|
|
onPressLike={this.props.onPressLike}
|
|
|
onContentSizeChange={(width, height) => {
|
|
|
this._updateScrollableTableViewHeight(0);
|
|
|
}}
|
|
|
onContentSizeChange={(width, height) => {}}
|
|
|
/>
|
|
|
<SectionList
|
|
|
ref={(c) => {
|
...
|
...
|
@@ -228,9 +226,7 @@ export default class Section extends React.Component { |
|
|
onPressSectionTag={this.props.onPressSectionTag}
|
|
|
onPressComment={this.props.onPressComment}
|
|
|
onPressLike={this.props.onPressLike}
|
|
|
onContentSizeChange={(width, height) => {
|
|
|
this._updateScrollableTableViewHeight(1);
|
|
|
}}
|
|
|
onContentSizeChange={(width, height) => {}}
|
|
|
/>
|
|
|
</ScrollableTabView>
|
|
|
);
|
...
|
...
|
@@ -246,7 +242,7 @@ export default class Section extends React.Component { |
|
|
<SectionTabBar
|
|
|
style={{borderBottomWidth: 0.5, borderBottomColor: '#e0e0e0',}}
|
|
|
tabs={this.tabs}
|
|
|
activeTab={this.state.currentPage}
|
|
|
activeTab={this.currentPage}
|
|
|
scrollValue={this.state.scrollValue}
|
|
|
goToPage={(page) => this._goToPage(page)}
|
|
|
/>
|
...
|
...
|
@@ -263,6 +259,10 @@ export default class Section extends React.Component { |
|
|
}
|
|
|
|
|
|
_goToPage(page) {
|
|
|
this.currentPage = page;
|
|
|
// this.setState({
|
|
|
// currentPage: this.currentPage,
|
|
|
// });
|
|
|
this.scrollableTabView && this.scrollableTabView.goToPage(page);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -270,37 +270,20 @@ export default class Section extends React.Component { |
|
|
this.state.scrollValue.setValue(value);
|
|
|
}
|
|
|
|
|
|
_updateScrollableTableViewHeight(tabIndex, onChangeTab = false) {
|
|
|
if (tabIndex > this.tabs.length - 1) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.timer = setTimeout(() => {
|
|
|
if (onChangeTab) {
|
|
|
this.currentPage = tabIndex;
|
|
|
this.setState({
|
|
|
currentPage: this.currentPage,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_getCurrentPageHeight(page) {
|
|
|
let ref = null;
|
|
|
if (tabIndex == 0) {
|
|
|
if (page == 0) {
|
|
|
ref = this.tab1;
|
|
|
} else {
|
|
|
ref = this.tab2;
|
|
|
}
|
|
|
|
|
|
if (!ref) {
|
|
|
return;
|
|
|
return this.initialPageHeight;
|
|
|
}
|
|
|
|
|
|
let height = ref.state.contentHeight;
|
|
|
this.scrollableTabView && this.scrollableTabView.setNativeProps({
|
|
|
style: {
|
|
|
height,
|
|
|
},
|
|
|
});
|
|
|
}, 300);
|
|
|
return height;
|
|
|
}
|
|
|
|
|
|
render() {
|
...
|
...
|
@@ -329,7 +312,7 @@ export default class Section extends React.Component { |
|
|
this.props.onRefresh && this.props.onRefresh();
|
|
|
}}
|
|
|
onEndReached={() => {
|
|
|
this.props.onEndReached && this.props.onEndReached(this.currentPage);
|
|
|
this.props.onEndReached && this.props.onEndReached(this.scrollableTabView.state.currentPage);
|
|
|
}}
|
|
|
renderFooter={() => {
|
|
|
if (endReached) {
|
...
|
...
|
|