Skip to content

Conversation

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Oct 3, 2019

Description

Implement the Android 10 Zoom transition.

Edit: The yellow tinge in the gif is an artifact from creating the gif.
resized_zoom_transition

To use this transition, add it your app's theme. For example, this is how you would do this with MaterialApp for Android devices:

MaterialApp(
  theme: ThemeData(
    pageTransitionsTheme: PageTransitionsTheme(
      builders: {
        TargetPlatform.android: ZoomPageTransitionsBuilder(),
      },
    ),
  ),
  // ...
);

Related Issues

Fixes #39812
Related to #40258
Related to #39858

Tests

I added the following tests:

  • A test to ensure that the ZoomPageTransition is used if specified in PageTransitionsTheme.

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.

TODO: implement reverse curve and further improve fastOutExtraSlowIn
curve to look more like native transition
@shihaohong shihaohong added platform-android Android applications specifically framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. work in progress; do not review labels Oct 3, 2019
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@shihaohong shihaohong changed the title WIP - [Android 10] Activity zoom transition [Android 10] Activity zoom transition Oct 14, 2019
@shihaohong shihaohong requested a review from HansMuller October 14, 2019 23:38
@shihaohong
Copy link
Contributor Author

I created a separate issue (#42802) to track setting page transition duration to a value other than 300ms, since the Android 10 activity transition is supposed to be over 400ms.

@Zazo032
Copy link
Contributor

Zazo032 commented Oct 15, 2019

@shihaohong
Copy link
Contributor Author

shihaohong commented Oct 15, 2019

@Zazo032 I was thinking of making this the default transition in a separate PR. Making that change would be breaking and involve some code and documentation changes. I would prefer to distinguish between the implementation details of the transition from making it the default Android transition for this PR.

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. Just a few comments about small stuff.

///
/// This tween sequence assumes that the evaluated result has to be a double
/// between 0.0 and 1.0.
class FlippedTweenSequence extends TweenSequence<double> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should also provide (separate PR) a FlippedTween, like ReverseTween:

class FlipTween<T> extends Tween<T> {
  FlipTween(this.parent)
    : assert(parent != null),
      super(begin: parent.end, end: parent.begin);

  final Tween<T> parent;

  @override
  T lerp(double t) => 1.0 - parent.lerp(1.0 - t);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an issue to track this: #43011

super(items);

@override
double transform(double t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this just

double transform(double t) => 1 - super.transform(1 - t);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is indeed just that. Updated it

end: 0.60,
);

// A curve sequence similar to the 'fastOutExtraSlowIn' curve used in the
Copy link
Contributor

Choose a reason for hiding this comment

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

similar => that's similar

/// * [OpenUpwardsPageTransitionsBuilder], which defines a page transition
/// that's similar to the one provided by Android P.
/// * [ZoomPageTransitionsBuilder], which defines a page transition similar
/// to the one provided in Android Q.
Copy link
Contributor

Choose a reason for hiding this comment

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

Android 10


@override
Widget build(BuildContext context) {
final Animation<double> _forwardScrimOpacityAnimation = _ZoomPageTransition._scrimOpacityTween
Copy link
Contributor

Choose a reason for hiding this comment

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

You could write these animations in terms of Animation.drive. For example:

final Animation<double> _forwardScrimOpacityAnimation = widget.animation.drive(
  CurveTween(curve: const Interval(0.2075, 0.4175)),
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a difference having these animations in terms of Animation.drive vs using Tween.animate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Animation.drive is consider to be a little easier to read. They're functionally the same.

});
}

bool get _transitionWasInterrupted {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be a good place to explain why we're checking if the transition was interrupted.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android 10] New transition when opening new activities

5 participants