Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement reverseTransitionDuration for TransitionRoute#48274

Merged
shihaohong merged 4 commits intoflutter:masterfrom
shihaohong:transition-route-reverse-duration
Jan 9, 2020
Merged

Implement reverseTransitionDuration for TransitionRoute#48274
shihaohong merged 4 commits intoflutter:masterfrom
shihaohong:transition-route-reverse-duration

Conversation

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Jan 7, 2020

Description

This change allows developers to implement a reverse duration for a page transition. It defaults to the forward transitionDuration if it isn't specified.

// SAMPLE CLASS: 
class ModifiedReverseTransitionDurationRoute<T> extends MaterialPageRoute<T> {
  ModifiedReverseTransitionDurationRoute({
    @required WidgetBuilder builder,
    RouteSettings settings,
    Duration reverseTransitionDuration,
    bool fullscreenDialog = false,
  }) : _reverseTransitionDuration = reverseTransitionDuration,
       super(
         builder: builder,
         settings: settings,
         fullscreenDialog: fullscreenDialog,
       );

  @override
  Duration get reverseTransitionDuration => _reverseTransitionDuration;
  final Duration _reverseTransitionDuration;
}

// USAGE:
Navigator.of(context).push(
  ModifiedReverseTransitionDurationRoute<dynamic>(
    builder: (BuildContext innerContext) {
      return Container(color: Colors.green);
    },
    reverseTransitionDuration: const Duration(milliseconds: 150), // modified value
  ),
);

Related Issues

n/a

Tests

I added the following tests:

Added a test for the default reverse transition duration
Added a test for a custom reverse transition duration

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

@shihaohong shihaohong added c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. labels Jan 7, 2020
final Completer<T> _transitionCompleter = Completer<T>();

/// The duration the transition lasts.
/// The duration the transition going forwards.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a "see also" section to link to reverseTransitionDuration?

/// The duration the transition going forwards.
Duration get transitionDuration;

/// The duration the transition going in reverse.
Copy link
Member

Choose a reason for hiding this comment

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

Mention the default and link it to transitionDuraiton?

);

@override
Duration get reverseTransitionDuration => _reverseTransitionDuration;
Copy link
Member

Choose a reason for hiding this comment

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

This and the next line could be simplified to:

@override
final Duration reverseTransitionDuration;

and then in the constructor you could just have this.reverseTransitionDuration.

@goderbauer
Copy link
Member

What does it look like when you have a transitionDuration of x and a reverseTransitionDuration of y and while the push of a route is ongoing you pop it again? Is there a jump in the animation? Or does it smoothly switch direction?

@shihaohong
Copy link
Contributor Author

shihaohong commented Jan 7, 2020

When you interrupt the push of a route that is ongoing with a pop, it does not cause a jump in animation if the animations are properly defined. For example, with ZoomPageTransitionsBuilder and FadeUpwardsTransitionsBuilder smoothly switch directions. The only difference was that the reverse transition duration was honored.

Edit:
I tested this by modifying the source code for MaterialPageRoute and added a reverseTransitionDuration override with a value different from transitionDuration. Then, I tested a Flutter app's page push/pop to see if there were any jumps in the animation with the mentioned animations.

@Piinks Piinks added f: routes Navigator, Router, and related APIs. a: animation Animation APIs labels Jan 8, 2020
Copy link
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

Maybe add a simple test to ensure that we never break the smooth animation when you pop while a push is ongoing with different durations?

@shihaohong
Copy link
Contributor Author

@goderbauer I added the forward smooth transition test. PTAL

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

@shihaohong shihaohong merged commit 51e24a3 into flutter:master Jan 9, 2020
@shihaohong shihaohong deleted the transition-route-reverse-duration branch January 9, 2020 17:31
bkonyi pushed a commit that referenced this pull request Jan 9, 2020
* Implement reverseTransitionDuration in TransitionRoute
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: animation Animation APIs c: new feature Nothing broken; request for a new capability 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.

4 participants