[web][ck] Don't remove (then add) embedded views. (flutter/engine#32948)

This commit is contained in:
David Iglesias
2022-04-27 11:09:05 -07:00
committed by GitHub
parent 68d58c0af0
commit 8109f3937f
2 changed files with 48 additions and 4 deletions

View File

@@ -997,9 +997,14 @@ ViewListDiffResult? diffViewList(List<int> active, List<int> next) {
}
}
}
// Remove all ids from viewsToRemove that also exist in viewsToAdd.
final List<int> viewsToAdd = next.sublist(active.length - index);
final Set<int> viewsToAddSet = viewsToAdd.toSet();
final List<int> viewsToRemove = active.sublist(0, index).where((int e) => !viewsToAddSet.contains(e)).toList();
return ViewListDiffResult(
active.sublist(0, index),
next.sublist(active.length - index),
viewsToRemove,
viewsToAdd,
false,
);
}
@@ -1011,9 +1016,15 @@ ViewListDiffResult? diffViewList(List<int> active, List<int> next) {
return null;
}
}
// Remove all ids from viewsToRemove that also exist in viewsToAdd.
final List<int> viewsToAdd = active.sublist(index + 1);
final Set<int> viewsToAddSet = viewsToAdd.toSet();
final List<int> viewsToRemove = next.sublist(0, next.length - index - 1).where((int e) => !viewsToAddSet.contains(e)).toList();
return ViewListDiffResult(
active.sublist(index + 1),
next.sublist(0, next.length - index - 1),
viewsToAdd,
viewsToRemove,
true,
viewToInsertBefore: active.first,
);

View File

@@ -581,6 +581,39 @@ void testMain() {
expect(result, isNull);
});
test('diffViewList works for flutter/flutter#101580', () {
ViewListDiffResult? result;
// Reverse the list
result = diffViewList(<int>[1, 2, 3, 4], <int>[4, 3, 2, 1]);
expect(result, isNotNull);
expect(result!.viewsToAdd, <int>[3, 2, 1]);
expect(result.viewsToRemove, isEmpty);
expect(result.addToBeginning, isFalse);
// Sort the list
result = diffViewList(<int>[3, 4, 1, 2], <int>[1, 2, 3, 4]);
expect(result, isNotNull);
expect(result!.viewsToAdd, <int>[3, 4]);
expect(result.viewsToRemove, isEmpty);
expect(result.addToBeginning, isFalse);
// Move last view to the beginning
// (The algo explores the diff from left to right, but in this case, it'd
// more efficient to add [1] at the beginning. Maybe we should compute both
// diffs, from left and right, and return the one that results in fewer
// add/remove operations?)
result = diffViewList(<int>[2, 3, 4, 1], <int>[1, 2, 3, 4]);
expect(result, isNotNull);
expect(result!.viewsToAdd, <int>[2, 3, 4]);
expect(result.viewsToRemove, isEmpty);
expect(result.addToBeginning, isFalse);
// Shuffle the list
result = diffViewList(<int>[1, 2, 3, 4], <int>[2, 4, 1, 3]);
expect(result, isNull);
});
test('does not crash when a prerolled platform view is not composited',
() async {
ui.platformViewRegistry.registerViewFactory(