Skip to content

Fix curve for popping heroes - #39844

Merged
goderbauer merged 1 commit into
flutter:masterfrom
goderbauer:heroCurve
Sep 11, 2019
Merged

goderbauer merged 1 commit into
flutter:masterfrom
goderbauer:heroCurve

Conversation

@goderbauer

Copy link
Copy Markdown
Member

Description

When popping a route with a Hero the Hero should animate back to its original place using a curve of Curves.fastOutSlowIn. Prior to this change, the hero would actually use the flipped curve of that (Curves.fastOutSlowIn.flipped).

Related Issues

None

Tests

I added the following tests:

  • Updated existing tests that where testing the wrong thing.
  • Added a new test for the popping curve.

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 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

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 4, 2019
@goderbauer goderbauer changed the title Fix curve for popping hero Fix curve for popping heroes Sep 4, 2019
final CreateRectTween createRectTween;
final HeroFlightShuttleBuilder shuttleBuilder;
final bool isUserGestureTransition;
final bool isDiverted;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this documented somewhere else? It's not immediately obvious what it means.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's documented more prominently here:

// While this flight's hero was in transition a push or a pop occurred for
// routes with the same hero. Redirect the in-flight hero to the new toRoute.
void divert(_HeroFlightManifest newManifest) {

@dnfield dnfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with question - if it's not documented anywhere else maybe we could document it here for now?

@shihaohong shihaohong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just had a few questions, but the rest of the changes look good

if (toHeroes[tag] != null) {
final HeroFlightShuttleBuilder fromShuttleBuilder = fromHeroes[tag].widget.flightShuttleBuilder;
final HeroFlightShuttleBuilder toShuttleBuilder = toHeroes[tag].widget.flightShuttleBuilder;
final bool isDiverted = _flights[tag] != null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Line 832 has _flights[tag] != null as a condition as well, but since it's in a different if/else block, it means something completely different (isAborted).

I'm not sure if this is a real issue or not, but the first time I looked at it, I was a little confused

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

_flights[tag] != null means there's currently a hero in-flight with the given tag. If toHeroes[tag] != null we have a new to destination for that hero, so we divert it. If toHeroes[tag] == null the in-flight hero is no longer contained in the destination route. Therefore, we don't have a to destination for the flying hero anymore and we abort its flight. Hope this makes sense.

return CurvedAnimation(
parent: (type == HeroFlightDirection.push) ? toRoute.animation : fromRoute.animation,
curve: Curves.fastOutSlowIn,
reverseCurve: isDiverted ? null : Curves.fastOutSlowIn.flipped,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean diverted heroes use Curves.fastOutSlowIn as a reverseCurve? When does this actually happen?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. A diverted hero is a hero that was in-flight and as it was flying got a new destination assigned to it. This can happen when you push a route and as the route is transitioning in you pop it again. The hero would start flying to the newly pushed route, but then as that one is popped fly back to where it came from. Usually, the pop should use the reverse curve, but in this particular case we do not want to switch curves as that would make the hero jump from the position it had on curve to the one it had on reverseCurve.

@codecov

codecov Bot commented Sep 10, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #39844 into master will increase coverage by 1.06%.
The diff coverage is 63.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #39844      +/-   ##
==========================================
+ Coverage   57.89%   58.96%   +1.06%     
==========================================
  Files         194      192       -2     
  Lines       18691    18443     -248     
==========================================
+ Hits        10822    10875      +53     
+ Misses       7869     7568     -301
Flag Coverage Δ
#flutter_tool 58.96% <63.46%> (+1.06%) ⬆️
Impacted Files Coverage Δ
...ackages/flutter_tools/lib/src/commands/unpack.dart 4.95% <ø> (ø) ⬆️
packages/flutter_tools/lib/src/version.dart 88.99% <ø> (-3.83%) ⬇️
packages/flutter_tools/lib/src/cache.dart 44.23% <ø> (ø) ⬆️
packages/flutter_tools/lib/src/plugins.dart 78.08% <0%> (ø) ⬆️
...ges/flutter_tools/lib/src/build_runner/web_fs.dart 21.96% <0%> (-2.09%) ⬇️
...utter_tools/lib/src/build_runner/build_runner.dart 0% <0%> (ø) ⬆️
packages/flutter_tools/lib/src/test/runner.dart 0% <0%> (ø) ⬆️
...lib/src/build_runner/web_compilation_delegate.dart 25.39% <0%> (+11.23%) ⬆️
...er_tools/lib/src/build_system/targets/windows.dart 94.11% <100%> (+0.36%) ⬆️
...utter_tools/lib/src/macos/cocoapods_validator.dart 82.6% <100%> (+0.79%) ⬆️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9d9156...cba671b. Read the comment docs.

@goderbauer
goderbauer merged commit 6dc9bf0 into flutter:master Sep 11, 2019
@goderbauer
goderbauer deleted the heroCurve branch September 11, 2019 21:56
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants