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

Fix TabBarView and TabBar animations are not synchronized #122021

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Mar 6, 2023

Description

This PR makes it possible to interrupt an ongoing TabBarView animation.
Before this PR, when the TabBarView animation is running (after the user selected one tab in the tab bar), it is not possible to interrupt this animation. So if the user selects another tab, the TabBarView will first finish the ongoing animation and then starts the new one). Because the TabBar animation can be interrupted, this leads to TabBarView and TabBar animations being unsynchronized.

Before:

Before.mp4

After:

After.mp4

Related Issue

Fixes #113020

Implementation choices

This PR combines several changes.

  1. A refactoring to make the code more understandable.
  2. _warpToIndex can be now called when there is already a warp underway, the new warp will interrupt the preceding one (This is the problem reported in TabController's index and animation is not working properly when a new tab is selected while there is a transition still occurring #113020).
  3. A debatable choice was to make an aggressive simplification by removing the logic related to caching the children list (removal of _children and originalChildren). Recreating _childrenWithKey by calling ensureUniqueKeysForList seems to be cheap and less error-prone.

Tests

Adds 1 test.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 6, 2023
@bleroux bleroux marked this pull request as draft March 6, 2023 15:48
@bleroux bleroux force-pushed the fix_tabbarview_and_tabbar_animations_not_synchronized branch from 769f0eb to 5267751 Compare March 6, 2023 20:21
@bleroux bleroux marked this pull request as ready for review March 6, 2023 21:13
@bleroux bleroux requested a review from HansMuller March 6, 2023 21:13
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

[Sorry: I seem to have forgotten to review this one.]

@HansMuller HansMuller merged commit 5d10cc2 into flutter:master Mar 15, 2023
@bleroux bleroux deleted the fix_tabbarview_and_tabbar_animations_not_synchronized branch March 15, 2023 18:26
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
2 participants