Skip to content

Commit 75fdab3

Browse files
author
石破天惊
authored
Merge pull request #69 from bolan9999/develop
Fix section error when reloadData
2 parents f62158b + 66ba589 commit 75fdab3

File tree

8 files changed

+49
-36
lines changed

8 files changed

+49
-36
lines changed

README-cn.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ onScroll | ({nativeEvent:{contentOffset:{x:number,y:number}}})=> any | | 滑动
344344

345345
## 更新日志
346346

347+
### 版本 1.2.5
348+
* 修复reloadData有时Section样式不正确的问题
349+
347350
### 版本 1.2.4
348351
* 修复初始化时是空视图,numberOfCellPoolSize默认值过小的问题
349352

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ Get LargeList's footer height
336336

337337
## Update Log
338338

339+
### Version 1.2.5
340+
* Fix section error when reloadData
341+
339342
### Version 1.2.4
340343
* Fix default numberOfCellPoolSize error when empty.
341344

ios/LargeListDemo/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1818
{
1919
NSURL *jsCodeLocation;
2020
#ifdef DEBUG
21-
// jsCodeLocation = [NSURL URLWithString:@"http://10.16.64.93:8081/index.bundle?platform=ios&dev=true"];
22-
jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.103:8081/index.bundle?platform=ios&dev=true"];
21+
jsCodeLocation = [NSURL URLWithString:@"http://10.16.64.93:8081/index.bundle?platform=ios&dev=true"];
22+
// jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.103:8081/index.bundle?platform=ios&dev=true"];
2323
// jsCodeLocation = [NSURL URLWithString:@"http://172.20.10.4:8081/index.bundle?platform=ios&dev=true"];
2424
#else
2525
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

react-native-largelist/largelist/LargeList.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,11 @@ class LargeList extends React.Component {
259259
this.contentSize.height += this.headerHeight;
260260
this.contentSize.height += this.footerHeight;
261261
this.safeArea.top = this.safeArea.bottom = this.headerHeight;
262-
this._onScroll({ nativeEvent: { contentOffset: this.contentOffset } });
263262
this.forceUpdate();
263+
this._onScroll(
264+
{ nativeEvent: { contentOffset: this.contentOffset } },
265+
true
266+
);
264267
}
265268

266269
componentDidUpdate() {
@@ -388,21 +391,24 @@ class LargeList extends React.Component {
388391
renderSection={this.props.renderSection}
389392
ref={reference => (this.currentSectionRef = reference)}
390393
numberOfSections={this.numberOfSections}
394+
heightForSection={this.props.heightForSection}
391395
/>
392396
</ScrollView>
393397
</View>
394398
);
395399
}
396400

397401
_createSection(section: number, top: number, refs: LargeListSection[]) {
402+
let height = section>=0 && section< this.numberOfSections() ? this.props.heightForSection(section):0;
398403
return (
399404
<LargeListSection
400405
ref={reference => reference && refs.push(reference)}
401406
key={this.keyForCreating++}
402-
style={[styles.absoluteStretch, { top: top }]}
407+
style={[styles.absoluteStretch, { top: top, height:height }]}
403408
numberOfSections={this.numberOfSections}
404409
section={section}
405410
renderSection={this.props.renderSection}
411+
heightForSection={this.props.heightForSection}
406412
/>
407413
);
408414
}
@@ -436,13 +442,13 @@ class LargeList extends React.Component {
436442
_onCellTouchBegin(sender) {
437443
let hide = false;
438444
this.workRefs.forEach(item => {
439-
let res = item.hideOther(sender);
445+
let res = item.hideOther(sender);
440446
if (!hide) hide = res;
441447
});
442448
return hide;
443449
}
444450

445-
_onScroll(e, withoutReload) {
451+
_onScroll(e, forceUpdate) {
446452
let offset: Offset = e.nativeEvent.contentOffset;
447453
if (this.empty || !this.sizeConfirmed) {
448454
this.contentOffset = offset;
@@ -462,6 +468,7 @@ class LargeList extends React.Component {
462468
this.lastScrollTime = now;
463469
let reloadType: number = 0;
464470
if (
471+
forceUpdate ||
465472
offset.y < topMargin ||
466473
offset.y + this.size.height + bottomMargin > this.contentSize.height ||
467474
speed < this.props.speedLevel1
@@ -712,16 +719,14 @@ class LargeList extends React.Component {
712719
if (section.top !== -10000)
713720
section.updateToSection(section.section, -10000, section.height, false);
714721
});
715-
716-
if (!withoutReload)
717-
switch (reloadType) {
718-
case 0:
719-
this._forceUpdate();
720-
break;
721-
default:
722-
this._positionUpdate();
723-
break;
724-
}
722+
switch (reloadType) {
723+
case 0:
724+
this._forceUpdate();
725+
break;
726+
default:
727+
this._positionUpdate();
728+
break;
729+
}
725730
this.contentOffset = offset;
726731
this.props.onScroll && this.props.onScroll(e);
727732
//解决冲量结束无法回调的问题
@@ -888,7 +893,6 @@ class LargeList extends React.Component {
888893
) {
889894
this.sizeConfirmed = true;
890895
this.initCells();
891-
// setTimeout( ()=>this._forceUpdate(),2000);
892896
}
893897
}
894898

@@ -948,8 +952,7 @@ class LargeList extends React.Component {
948952
if (offset.y > this.contentSize.height - this.size.height)
949953
offset.y = this.contentSize.height - this.size.height;
950954
if (!animated) {
951-
this._onScroll({ nativeEvent: { contentOffset: offset } });
952-
this._forceUpdate();
955+
this._onScroll({ nativeEvent: { contentOffset: offset } }, true);
953956
}
954957
this.scrollViewRef.scrollTo(offset);
955958
}
@@ -1019,7 +1022,6 @@ class LargeList extends React.Component {
10191022
this.initVar();
10201023
this.safeArea = { top: 0, bottom: 0 };
10211024
this.workRefs.forEach(cell => {
1022-
// this.freeRefs.splice(0, 0, cell);
10231025
this.freeRefs.push(cell);
10241026
});
10251027
this.freeRefs.forEach(cell => {

react-native-largelist/largelist/LargeListCell.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class LargeListCell extends React.Component {
107107
componentDidUpdate() {
108108
if (this._shouldScrollToCenter && this.contentSize.width) {
109109
this._enableShowEx = false;
110+
this._shouldScrollToCenter = false;
110111
let timer = setTimeout(() => {
111112
if (this._showLeft) {
112113
this._scrollToShowLeft(false);
@@ -126,9 +127,7 @@ class LargeListCell extends React.Component {
126127

127128
render() {
128129
let { section, row } = this.indexPath;
129-
let show =
130-
// this.top !== -10000 &&
131-
section >= 0 &&
130+
let show = section >= 0 &&
132131
section < this.props.numberOfSections() &&
133132
row >= 0 &&
134133
row < this.props.numberOfRowsInSection(section);
@@ -234,8 +233,10 @@ class LargeListCell extends React.Component {
234233
_onLayout(e) {
235234
if (this.contentSize.width !== e.nativeEvent.layout.width) {
236235
this.contentSize = { ...e.nativeEvent.layout };
237-
this._shouldScrollToCenter = true;
238-
this.forceUpdate();
236+
if (this._lWidth()>0) {
237+
this._shouldScrollToCenter = true;
238+
this.forceUpdate();
239+
}
239240
}
240241
}
241242

react-native-largelist/largelist/LargeListSection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class LargeListSection extends React.Component {
2020
static propTypes = {
2121
numberOfSections: PropTypes.func,
2222
renderSection: PropTypes.func,
23-
section: PropTypes.number
23+
section: PropTypes.number,
24+
heightForSection: PropTypes.func,
2425
};
2526

2627
rootView: View;
@@ -36,7 +37,6 @@ class LargeListSection extends React.Component {
3637
style: { top: this.top, height: this.height }
3738
});
3839
this.waitForRender = false;
39-
4040
this.forceUpdate();
4141
}
4242

@@ -71,8 +71,8 @@ class LargeListSection extends React.Component {
7171
}
7272

7373
render() {
74-
// let show = this.section>=0 && this.top !== -10000;
75-
let show = this.section>=0 && this.section<this.props.numberOfSections() && this.top !== -10000;
74+
let show = this.section>=0 && this.section<this.props.numberOfSections();// && this.top !== -10000;
75+
if (show && !this.height) this.height = this.props.heightForSection(this.section);
7676
return (
7777
<View
7878
ref={ref => (this.rootView = ref)}

react-native-largelist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-largelist",
3-
"version": "1.2.3",
3+
"version": "1.2.5",
44
"private": false,
55
"description": "The best performance large list component which is much better than SectionList for React Native.",
66
"author": "bolan9999 <[email protected]>",

samples/LargeListSample4.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ class LargeListSample4 extends React.Component {
7070
alignItems: "center"
7171
}}
7272
onPress={() => {
73-
this.listRef.scrollToIndexPath({ section: row, row: 0 });
73+
// this.listRef.scrollToIndexPath({ section: row, row: 0 });
74+
foods[row].selected = true;
75+
foods[this.selectedIndex].selected = false;
76+
this.selectedIndex = row;
77+
this.indexes.reloadData();
7478
}}
7579
>
7680
<Text style={{ fontSize: 18 }} fontWeight={300}>
@@ -166,13 +170,13 @@ class LargeListSample4 extends React.Component {
166170
foods[this.selectedIndex].selected = false;
167171
foods[section].selected = true;
168172
// 使用局部更新
169-
this.indexes.reloadIndexPaths([
170-
{ section: 0, row: this.selectedIndex },
171-
{ section: 0, row: section }
172-
]);
173+
// this.indexes.reloadIndexPaths([
174+
// { section: 0, row: this.selectedIndex },
175+
// { section: 0, row: section }
176+
// ]);
173177
this.selectedIndex = section;
174178
// 使用更新所有数据源
175-
// this.indexes.reloadData();
179+
this.indexes.reloadData();
176180

177181
let bFind = false;
178182
this.indexes.visibleIndexPaths().forEach(indexPath=>{

0 commit comments

Comments
 (0)