Sitelet https://web.archive.org/web/20210209174302/https://github.com/flutter/flutter/pull/71864
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore sliver underflow if the last children is no longer at the prev… #71864

Merged
merged 9 commits into from Feb 9, 2021

Conversation

@chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Dec 7, 2020

…ious last index

Description

When sliver underflow, it will try to build one more child after the current last child. If the last child got moved to other place, the sliver will still try to build one more child after the new location. This PR fixes it.

Open Question: is the current underflow logic still valid? the sliver render object marks sliver element underflow, but it only gets picked on the next rebuild. if the sliver does not rebuild, nothing will change. and if the sliver does rebuild, the information may be outdated due to children reorder. I am not familiar with the underflow to make an improvement. Any advice?

Related Issues

fixes #71273

Tests

I added the following tests:

see files

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@google-cla google-cla bot added the cla: yes label Dec 7, 2020
@chunhtai chunhtai requested review from goderbauer and HansMuller Dec 7, 2020
@@ -1185,7 +1185,10 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render

renderObject.debugChildIntegrityEnabled = false; // Moving children will temporary violate the integrity.
newChildren.keys.forEach(processElement);
if (_didUnderflow) {
final int newLastIndex = _childElements.lastKey() ?? -1;
// We don't worry about underflow if the last child is not longer at the

This comment has been minimized.

@goderbauer

goderbauer Dec 8, 2020
Member

Why do we not worry about underflow in this condition?

This comment has been minimized.

@chunhtai

chunhtai Dec 8, 2020
Author Contributor

I am not entirely sure about the reason why we have the underflow logic, I can only guess by how it is used.

It seems like render sliver list set it to true when it think it has reached the end of the child list. Thus, if the children are reordered, the previous last child is moved to other place, and we no longer at the end of the child list, we should ignore this request.

Am I missing something?

This comment has been minimized.

@chunhtai

chunhtai Dec 15, 2020
Author Contributor

underflow is there to ensure children rebuild will update max scroll offset

for example if you have a list of 10 items, and you scrolled to the end of the list.
If we add an item to the end of the list, the sliver element rebuild will not change its child elements because it will only update its existing children. Since the children does not change during the rebuild, we will skip layout phase. Thus the max scroll offset will not get update, user will not be able to scroll to the 11th child.

That is why we proactively build one more child at the end to ensure the max scroll offset is updated.

This logic is not needed when "any" of the children gets updated, because it will trigger a layout. I will update the logic

@chunhtai chunhtai force-pushed the chunhtai:issues/71273 branch from 75fd177 to 5e3bb8b Dec 16, 2020
@chunhtai
Copy link
Contributor Author

@chunhtai chunhtai commented Jan 22, 2021

A friendly bump

@chunhtai chunhtai force-pushed the chunhtai:issues/71273 branch from 5e3bb8b to fa26bb8 Jan 22, 2021
@chunhtai
Copy link
Contributor Author

@chunhtai chunhtai commented Jan 28, 2021

Hi @goderbauer can you take another look at this pr?

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:collection/collection.dart';

This comment has been minimized.

@goderbauer

goderbauer Jan 28, 2021
Member

Are you importing this only for ListEquals? use listEquals from flutter/foundation.dart instead.

@@ -1185,7 +1188,8 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render

renderObject.debugChildIntegrityEnabled = false; // Moving children will temporary violate the integrity.
newChildren.keys.forEach(processElement);
if (_didUnderflow) {
// We don't worry about underflow if any child has been updated.

This comment has been minimized.

@goderbauer

goderbauer Jan 28, 2021
Member

This comment should include an explanation why the underflow doesn't matter if children get updated.

@chunhtai chunhtai force-pushed the chunhtai:issues/71273 branch from fa26bb8 to 31d2506 Jan 28, 2021
@chunhtai
Copy link
Contributor Author

@chunhtai chunhtai commented Jan 28, 2021

thanks @goderbauer ! i addressed all comments

Copy link
Member

@goderbauer goderbauer left a comment

LGTM

@@ -1185,7 +1188,16 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render

renderObject.debugChildIntegrityEnabled = false; // Moving children will temporary violate the integrity.
newChildren.keys.forEach(processElement);
if (_didUnderflow) {
// A element rebuild only updates existing children. The underflow check

This comment has been minimized.

@goderbauer

goderbauer Feb 3, 2021
Member

A element -> An element

@fluttergithubbot
Copy link
Contributor

@fluttergithubbot fluttergithubbot commented Feb 5, 2021

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux build_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux web_long_running_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux flutter_plugins has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Mac build_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Windows build_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.
chunhtai added 9 commits Dec 7, 2020
@chunhtai chunhtai force-pushed the chunhtai:issues/71273 branch from 882bdee to 8bff744 Feb 8, 2021
@fluttergithubbot fluttergithubbot merged commit a65ce5b into flutter:master Feb 9, 2021
33 checks passed
33 checks passed
Linux analyze
Details
Linux build_tests
Details
Linux customer_testing
Details
Linux docs
Details
Linux firebase_abstract_method_smoke_test
Details
Linux firebase_android_embedding_v2_smoke_test
Details
Linux firebase_release_smoke_test
Details
Linux flutter_plugins
Details
Linux framework_tests
Details
Linux fuchsia_precache
Details
Linux web_e2e_test
Details
Linux web_integration_tests
Details
Linux web_long_running_tests
Details
Linux web_smoke_test
Details
Linux web_tests
Details
Mac build_tests
Details
Mac customer_testing
Details
Mac framework_tests
Details
WIP Ready for review
Details
Windows build_tests
Details
Windows customer_testing
Details
Windows framework_tests
Details
analyze-linux Task Summary
Details
cla/google All necessary CLAs are signed
customer_testing-linux Task Summary
Details
docs-linux Task Summary
Details
flutter-build Flutter build is currently broken. Please do not merge this PR unless it contains a fix to the broken build.
Details
flutter-gold All golden file tests have passed.
Details
framework_tests-libraries-linux Task Summary
Details
framework_tests-misc-linux Task Summary
Details
framework_tests-widgets-linux Task Summary
Details
web_integration_tests Task Summary
Details
web_smoke_test Task Summary
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants