Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 23ac4aa

Browse files
author
Yuncong Zhang
authored
Merge pull request #337 from UnityTech/fix_keep_alive_bug_full
fix keep alive bug (full fix)
2 parents 06e3213 + 9bdce8a commit 23ac4aa

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Runtime/rendering/sliver_multi_box_adaptor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ public class SliverMultiBoxAdaptorParentData : ContainerParentDataMixinSliverLog
3636

3737
public bool keepAlive = false;
3838

39-
internal bool _keptAlive = false;
39+
public bool keptAlive {
40+
get { return this._keptAlive; }
41+
}
4042

43+
internal bool _keptAlive = false;
44+
4145
public override string ToString() {
4246
return $"index={this.index}; {(this.keepAlive ? "keeyAlive; " : "")}{base.ToString()}";
4347
}
@@ -80,6 +84,7 @@ bool _debugAssertChildListLocked() {
8084
}
8185

8286
public override void insert(RenderBox child, RenderBox after = null) {
87+
D.assert(!this._keepAliveBucket.ContainsValue(value: child));
8388
base.insert(child, after: after);
8489
D.assert(this.firstChild != null);
8590
D.assert(() => {

Runtime/widgets/sliver.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,27 @@ protected override void performRebuild() {
355355
this._currentBeforeChild = null;
356356
D.assert(this._currentlyUpdatingChildIndex == null);
357357
try {
358-
int firstIndex = 0;
359-
int lastIndex = 0;
360-
361-
if (!this._childElements.isEmpty()) {
362-
firstIndex = this._childElements.First().Key;
363-
lastIndex = this._childElements.Last().Key;
364-
if (this._didUnderflow) {
365-
lastIndex += 1;
366-
}
367-
}
368-
369-
for (int index = firstIndex; index <= lastIndex; ++index) {
358+
void processElement(int index) {
370359
this._currentlyUpdatingChildIndex = index;
371360
Element newChild = this.updateChild(this._childElements.getOrDefault(index), this._build(index),
372361
index);
373362
if (newChild != null) {
374363
this._childElements[index] = newChild;
375-
this._currentBeforeChild = (RenderBox) newChild.renderObject;
364+
var parentData = (SliverMultiBoxAdaptorParentData) newChild.renderObject.parentData;
365+
if (!parentData.keptAlive) {
366+
this._currentBeforeChild = (RenderBox) newChild.renderObject;
367+
}
376368
}
377369
else {
378370
this._childElements.Remove(index);
379371
}
380372
}
373+
// processElement may modify the Map - need to do a .toList() here.
374+
this._childElements.Keys.ToList().ForEach(action: processElement);
375+
if (this._didUnderflow) {
376+
var lastKey = this._childElements?.Last().Key ?? -1;
377+
processElement(lastKey + 1);
378+
}
381379
}
382380
finally {
383381
this._currentlyUpdatingChildIndex = null;

0 commit comments

Comments
 (0)