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

Shared Z Axis Transition #57

Merged
merged 24 commits into from
Jan 2, 2020
Merged

Conversation

shihaohong
Copy link

Implement the shared z axis transition:
shared z axis

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.

This PR looks good, all of the feedback is small stuff.


import 'utils/curves.dart';

/// Used by [PageTransitionsTheme] to define a page route transition animation
Copy link
Contributor

Choose a reason for hiding this comment

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

I think mentioning [SharedZAxisTransition] here would be worthwhile.

/// ),
/// );
/// },
/// '/a' : (BuildContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

extra space before :

/// return Container(
/// color: Colors.red,
/// child: Center(
/// child: MaterialButton(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use MaterialButton (here and below), it's a leftover. RaisedButton, FlatButton, or OutlineButton would be OK.

}
}

/// Defines a transition in which outgoing and incoming elements share a scale
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a true statement however maybe it's possible to craft something that's a little more specific? Here and above.

///
/// The shared axis pattern provides the transition animation between UI elements
/// that have a spatial or navigational relationship. For example,
/// transitioning from one page of a sign up page to the next one.
Copy link
Contributor

Choose a reason for hiding this comment

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

sign-up

super.dispose();
}

static final Tween<double> _flippedTween = Tween<double>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Tweens are mutable. Even though you don't, it might be a little safer (future) to just create the Tween inline in _flip().

void dispose() {
widget.animation.removeStatusListener(_animationListener);
widget.secondaryAnimation.removeStatusListener(_secondaryAnimationListener);
super.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this widget have been disposed while the animation (the AnimatedBuilder) is still running?

I think this is safe, since dispose implies that the AnimatedBuilder is disposed as well. It would be good to test this part of the implementation (rebuild a widget with and then without the transition, while the transition is underway).

Copy link
Author

Choose a reason for hiding this comment

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

I added a test for this. PTAL

final Animation<double> animation;
final Widget child;

static Animatable<double> fadeInTransition = CurveTween(curve: decelerateEasing)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment about static tweens (here and elsewhere). Maybe just create these in the build method.

// Jump 3/10ths of the way through the transition, bottom route
// should be be completely faded out while the top route
// is also completely faded out.
// Transition time: 300ms, 3/10 * 300ms = 90ms
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

_TestWidget(navigatorKey: navigator),
);

navigator.currentState.pushNamed('/a');
Copy link
Contributor

Choose a reason for hiding this comment

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

pushNamed(topRoute)?

@shihaohong shihaohong mentioned this pull request Jan 2, 2020
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

@override
void didUpdateWidget(SharedZAxisTransition oldWidget) {
super.didUpdateWidget(oldWidget);
void _updateAnimationListener(SharedZAxisTransition oldWidget) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine however what I meant (but muddled) was:

void _updateAnimationListener(Animation<double> oldAnimation, Animation<double> animation) {
  if (oldAnimation != animation) {
    oldAnimation.removeStatusListener(_animationListener);
    animation.addStatusListener(_animationListener);
    _animationListener(animation.status);
  }
}

void didUpdateWidget(SharedZAxisTransition oldWidget) {
  super.didUpdateWidget(oldWidget);
  _updateAnimationListener(oldWidget.animation, widget.animation);
  _updateAnimationListener(oldWidget.secondaryAnimation, widget.secondaryAnimation);
}


static Animatable<double> scaleInTransition = Tween<double>(begin: 0.80, end: 1.00)
.chain(CurveTween(curve: standardEasing));
static Animatable<double> scaleInTransition =
Copy link
Contributor

Choose a reason for hiding this comment

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

Two-space indent ... I think this would be a little more conventional formatting-wise (here and below):

  static Animatable<double> fadeOutTransition = FlippedCurveTween(curve: accelerateEasing)
    .chain(CurveTween(curve: const Interval(0.0, 0.3)));

Copy link
Author

Choose a reason for hiding this comment

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

Done -- the formatted seemed to have removed my original formatting

@@ -49,8 +49,8 @@ class FlippedCurveTween extends CurveTween {
/// Creates a vertically flipped [CurveTween].
FlippedCurveTween({
@required Curve curve,
}) : assert(curve != null),
super(curve: curve);
}) : assert(curve != null),
Copy link
Contributor

Choose a reason for hiding this comment

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

extra spaces ended up here

Copy link
Author

Choose a reason for hiding this comment

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

What's weird is that the formatter suggested two spaces instead of one before the colon :. If not, the formatted complained and I'm unsure if that's a normal expectation for non-flutter/flutter projects or not

Copy link
Contributor

Choose a reason for hiding this comment

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

The Dart formatter doesn't really do conventional Flutter SDK formatting.

@shihaohong shihaohong merged commit a4084f0 into flutter:master Jan 2, 2020
@shihaohong shihaohong deleted the sharedZAxis branch January 2, 2020 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants