Skip to content

Commit eb7aa43

Browse files
author
soliury
committed
backup
1 parent 170ceb0 commit eb7aa43

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/components/ScrollableTabs.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ class ScrollableTabs extends Component {
4444
this.state.x.addListener((e)=> {
4545
if (e.value % (this.space + tabNavItemWidth) === 0) {
4646
let index = Math.abs(e.value / (this.space + tabNavItemWidth));
47-
typeof this.props.onPageChangedAndAnimateEnd === 'function' && this.props.onPageChangedAndAnimateEnd(index, this._isScrolling());
47+
typeof this.props.onPageChangedAndAnimateEnd === 'function' && this.props.onPageChangedAndAnimateEnd(index, this.isScrolling());
4848
}
4949
});
5050
this._navs = {};
5151
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
5252
}
5353

5454

55+
isScrolling() {
56+
return ()=> this._scrolling;
57+
}
58+
59+
5560
_updateNavScale(offset) {
5661
const space = this.space + this.props.tabNavItemWidth;
5762
this.props.tabs.forEach((item, index)=> {
@@ -67,7 +72,7 @@ class ScrollableTabs extends Component {
6772
scale = (max - offset) / space;
6873
}
6974

70-
if (offset == center) {
75+
if (offset === center) {
7176
scale = 1;
7277
}
7378
this._navs[index].setNativeProps({
@@ -92,12 +97,9 @@ class ScrollableTabs extends Component {
9297
}
9398

9499

95-
_isScrolling() {
96-
return ()=> this._scrolling;
97-
}
98-
99100
_onScroll(e) {
100101
const {x} = e.nativeEvent.contentOffset;
102+
this._scrolling = true;
101103
this._animateScroll(x);
102104
}
103105

@@ -116,7 +118,7 @@ class ScrollableTabs extends Component {
116118
this._animateScroll(offsetX);
117119
if (page !== this.index) {
118120
this._scrolling = false;
119-
typeof this.props.onPageChanged === 'function' && this.props.onPageChanged(page, this._isScrolling());
121+
typeof this.props.onPageChanged === 'function' && this.props.onPageChanged(page, this.isScrolling());
120122
}
121123
this.index = page;
122124
}
@@ -128,7 +130,7 @@ class ScrollableTabs extends Component {
128130
if (position === undefined) {
129131
return;
130132
}
131-
typeof this.props.onPageChanged === 'function' && this.props.onPageChanged(position, this._isScrolling());
133+
typeof this.props.onPageChanged === 'function' && this.props.onPageChanged(position, this.isScrolling());
132134
}
133135

134136

@@ -220,7 +222,7 @@ class ScrollableTabs extends Component {
220222
scrollEventThrottle={16}
221223
onScroll={this._onScroll.bind(this)}
222224
onMomentumScrollBegin={this._onMomentumScrollBegin.bind(this)}
223-
onMomentumScrollEnd={this._onMomentumScrollBegin.bind(this)}
225+
onMomentumScrollEnd={this._onMomentumScrollEnd.bind(this)}
224226
keyboardDismissMode="on-drag"
225227
>
226228

src/layouts/Home.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class Home extends Component {
3535
return (
3636
<TopicList router={this.props.router}
3737
key={item}
38-
tab={item}/>
38+
tab={item}
39+
isTabScrolling={()=> this._scrollableTabs.isScrolling()()}
40+
/>
3941
);
4042
});
4143
}
@@ -46,6 +48,7 @@ class Home extends Component {
4648
return (
4749
<View style={styles.container}>
4850
<ScrollableTabs
51+
ref={view=> this._scrollableTabs=view}
4952
index={0}
5053
tabs={['精华', '问答', '主页', '分享', '招聘']}
5154
onPageChangedAndAnimateEnd={this._onPageChanged.bind(this)}

src/layouts/TopicList.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,28 @@ class TopicList extends Component {
2323

2424
componentWillReceiveProps(nextProps) {
2525
if (nextProps.data !== this.props.data) {
26-
this.setState({
27-
ds: this.state.ds.cloneWithRows(nextProps.data)
28-
});
26+
this._updateData(nextProps.data);
2927
}
3028
}
3129

3230

31+
_updateData(data) {
32+
this.setState({
33+
ds: this.state.ds.cloneWithRows(data)
34+
});
35+
// if (!this.props.isTabScrolling()) {
36+
// this.setState({
37+
// ds: this.state.ds.cloneWithRows(data)
38+
// });
39+
// }
40+
// else {
41+
// setTimeout(()=> {
42+
// this._updateData(data);
43+
// }, 16);
44+
// }
45+
}
46+
47+
3348
_onEndReached() {
3449
const {tab, limit, page, actions, data} = this.props;
3550
if (data.length) {

0 commit comments

Comments
 (0)