Skip to content

fix initial routes do not run secondary animation when pops#47476

Merged
fluttergithubbot merged 9 commits intoflutter:masterfrom
chunhtai:issues/46000
Feb 5, 2020
Merged

fix initial routes do not run secondary animation when pops#47476
fluttergithubbot merged 9 commits intoflutter:masterfrom
chunhtai:issues/46000

Conversation

@chunhtai
Copy link
Copy Markdown
Contributor

@chunhtai chunhtai commented Dec 19, 2019

Description

Whenever a new route pushed on top of another route, it will chains the secondary animation of bottom route with the primary animation of top route. However, there is a bug in the method that chain them together. In the method, we try to do train hopping if the two animations does not have the same values. It is possible that the two animations are animating with different directions and the hopping will never happen, and that introduce this bug.

here are the steps, assume initial route is routeA/routeB
1, routeA pushed with pri-animation=1.0, sec-animation=0.0
2, routeB pushed with pri-animation=1.0, and it try to do train hopping on sec-animation of routeA which never happen. The sec-animation of routeA stay at 0.0
3, when routeB pop, the routeA didpopnext will try to do the train hopping again with sec-animation of routeA = 0.0 and pri-animation of routeB =1.0 in reverse order. This is wrong because the sec-animation of routeA should be 1.0 at this moment and animate with pri-animation of routeB.

Related Issues

Closes #46000

Tests

I added the following tests:
"secondary animation is triggered when pop initial route"

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.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 19, 2019
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@goderbauer you wrote this test. However, something is unclear what the expected behavior should be.
The last pop trigger a train hopping where pri-animation of top most route = 0.16 reverse and sec-animation of the route below =0.67 forward. They will never meet and sec-animation just hang there until everything is disposed. This is what it looks like in real world
ezgif com-video-to-gif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is what it looks like after this pr
ezgif com-video-to-gif (1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These animations both look broken.

@chunhtai chunhtai force-pushed the issues/46000 branch 2 times, most recently from 3120b98 to 1746735 Compare December 20, 2019 17:37
@chunhtai chunhtai requested a review from goderbauer December 20, 2019 18:09
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How do we know that the two trains will never cross in the future?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code below also doesn't seem to check that the trains will not cross in the future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The check is to detect whether they will cross with the current animations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test below only looks at the current value and the direction of the animation. How's that enough to determine if they will cross? AFIK, the animation values doesn't have to run monotonically from 0.0 to 1.0. It could bounce up and down in between?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to have the else branches here. I would write this as:

if (conditionA)
  return ...;
if (conditionB)
  return ...;
return ...;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These animations both look broken.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: remove extra blank line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we just need to change this condition to jump directly when the values are the same and to also just jump directly when the nextTrain animation is completed (meaning the next route appeared on top of this route without animation).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will only fix the initial route issue. what about the test below?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, right. So somehow we need to guarantee that we will jump even when the trains haven't crossed at the end of the animation.

@Piinks Piinks added a: animation Animation APIs f: routes Navigator, Router, and related APIs. labels Jan 8, 2020
@chunhtai chunhtai force-pushed the issues/46000 branch 3 times, most recently from 4532486 to 95a33c3 Compare January 27, 2020 18:03
@chunhtai
Copy link
Copy Markdown
Contributor Author

chunhtai commented Feb 4, 2020

@goderbauer This is blocking the work of navigator page api. When you re-arrange the routes and try to update the secondary animation it is really easy to hit this case where the train hopping never finishes because the animation of next route is already completed

Copy link
Copy Markdown
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How do you know at this point that there's an existing train hopping in progress?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

whoever calls this method will need to make sure to set this private field to null as to indicate there is no more train hopping in progress. I think the comment in line 253 is not clear enough, will update

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use _updateSecondaryAnimation to make it clear that you mean this method?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: end with .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it should be -> it has been

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: start with a capital letter ("Secondary").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we just set _trainHoppingListenerRemover to null at the very beginning of this method after we copied it into previousTrainHoppingListenerRemover?

@ldelafuente
Copy link
Copy Markdown

Hi @chunhtai , do you have a planned date to release this in the stable branch?
I tried patching routes.dart on the latest stable release with the insertions you made on this PR, but secondary animations still don't run for initial routes. Do these changes have dependencies on other files maybe?

I'm using nested navigators and the initial route doesn't pop even if I explicitly set initialRoute to false

@chunhtai
Copy link
Copy Markdown
Contributor Author

@ldelafuente This patch does not depend on other file, can you provide a runnable example that reproduce the problem you are having? I don't know when the next stable release will be yet

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: animation Animation APIs f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigator: initial route and secondary animation

6 participants