-
Notifications
You must be signed in to change notification settings - Fork 29.5k
_TabBarViewState should not recreate page controller #135500
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
_TabBarViewState should not recreate page controller #135500
Conversation
75f3b9d to
9cb5c6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will need to update current page index. probably through a jumpTo
I think you also need to recreate PageController if viewportFraction changes, but I think it should be done in didUpdateWidget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will need to update current page index. probably through a jumpTo
This is something I considered. I checked that, even without this PR, when the DefaultTabController is updated with a one with a different initialIndex this has a no impact on the current index.
Maybe I made a bad assumption, from my understanding didChangeDependencies will only be called when the TabController is provided via a DefaultTabController (because of the call to DefaultTabController.maybeOf(context);in _TabBarViewState._updateTabController. If this true, the only way to trigger didChangeDependencies would be similar to the one in the test I added, and there is no possibility to set a different index in this case (the current index is stored in the TabController stored in _DefaultTabControllerState).
I will do more investigation, I'm very interested to have your view on the above assumption.
I think you also need to recreate PageController if viewportFraction changes, but I think it should be done in didUpdateWidget.
Yes, I noticed this and I planned to file another issue to give more context and a PR to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a call to jumpToPage when the page controller is reused.
e32af61 to
d6f2e64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but the test should also check for index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also check whether the index is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chunhtai I consider it but I found it confusing to add this check in the test because, with or without the PR, the index will not change (DefaultTabCotnroller.initialIndex is read once when initializing the PageView).
I don't know if this is the correct behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the jumpTo will make it jump to whatever less rebuild index which is 14. This just to test the jumpTo is there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the jumpTo will make it jump to whatever less rebuild index which is 14
It won't because changing the DefaultTabController.initialPage has no impact on the page view current page index. Technically, it is because _DefaultTabControllerState.didUpdateWidget does not check if initialPage was changed. I would say it makes sense because changing the initialIndex does not mean changing the current index, but I don't have a strong opinion there.
For the moment, I have not find a case were the jumpTo added in this PR would be necessary (but it would if we decided that _DefaultTabControllerState.didUpdateWidget should update the selected page when DefaultTabController.initialPage is changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes. in this case, can you shorten the length to force it to update the index in controller?
for example, if current index is 10, you rebuild DefaultTabController with length 5, it should force the index to be 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly what I tried this morning 😄 .
In this case the index changes so I thought it will be ok to update the test accordingly... until I checked what happened if I remove the call to jumpTo: the index still change in this case because it is updated earlier (because of the logic in _DefaultTabControllerState.didUpdateWidget and because the viewport dimension change lead to a call to _PagePosition.forcePixels which correctly updates the scroll position on which the page computation is based).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You meant viewportFraction change? I can't figure out how the method is called in the update.
Either way, I think I will still put the check in this test. Even though it pass without the jumpTo, as long as it is checking correct behavior, it is worth adding there to prevent future regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totaly agree that it is worth adding this to prevent future regressions. I have updated the PR accordingly.
Many thanks for sharing your thoughts.
You meant viewportFraction change?
No, I meant when the length of the TabController is shortened, it has an impact on the page view content dimensions and the logic in _PagePosition.applyContentDimensions will take care of updating the page controller position (I was wrong mentionning forcePixels it is correctPixels which is called).
For posterity 😄 , the way to get deeper on this is to run the test in this PR. Then comment the call to jumpTo added in this PR and see that the test still pass. To understand why put a break point in ScrollPosition.correctPixels and re-run the test. The call stack will be the following one:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah this totally makes sense now, thanks for explanation.
d6f2e64 to
f744379
Compare
|
auto label is removed for flutter/flutter/135500, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label. |
9ca473d to
31fb55e
Compare
|
I can't really tell what may be wrong with the internal test. I need to investigate further to figure out. |
31fb55e to
13bc7ab
Compare
|
@bleroux can you update the branch to retrigger the ci. It looks like the google test was erased |
13bc7ab to
bbfbf4b
Compare
flutter/flutter@da0cd69...11def8e 2023-12-21 [email protected] Update README.md (flutter/flutter#140382) 2023-12-21 [email protected] Revert "Integrate testWidgets with leak tracking. (#138057)" (flutter/flutter#140502) 2023-12-21 [email protected] Integrate testWidgets with leak tracking. (flutter/flutter#138057) 2023-12-21 [email protected] Fix import pattern (flutter/flutter#140425) 2023-12-20 [email protected] Update job permissions (flutter/flutter#140476) 2023-12-20 [email protected] Roll pub packages (flutter/flutter#140472) 2023-12-20 [email protected] Remove outdated ignores from tool (flutter/flutter#140467) 2023-12-20 [email protected] Remove outdated ignores from framework (flutter/flutter#140465) 2023-12-20 [email protected] Reland `find.textRange.ofSubstring` changes (flutter/flutter#140469) 2023-12-20 [email protected] Part 1/n migration steps for kotlin migration (flutter/flutter#140452) 2023-12-20 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Make `TextSpan` hit testing precise." (flutter/flutter#140468) 2023-12-20 [email protected] [web] Re-enable test now that source of flakiness is fixed (flutter/flutter#140462) 2023-12-20 [email protected] Eliminate Cirrus build status badge (flutter/flutter#140461) 2023-12-20 [email protected] Move tests shifted to Pixel 7 from staging to prod (flutter/flutter#140438) 2023-12-20 [email protected] Roll Packages from be52ac8 to dc5b267 (5 revisions) (flutter/flutter#140450) 2023-12-20 [email protected] _TabBarViewState should not recreate page controller (flutter/flutter#135500) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
## Description This PR replaces the unconditional instantiation of `PageController` in `_TabBarViewState.didChangeDependencies` as suggested in flutter#134091 (comment). ## Related Issue Fixes flutter#134253. ## Tests Adds 1 test.

Description
This PR replaces the unconditional instantiation of
PageControllerin_TabBarViewState.didChangeDependenciesas suggested in #134091 (comment).Related Issue
Fixes #134253.
Tests
Adds 1 test.