Skip to content

Conversation

@xster
Copy link
Member

@xster xster commented Oct 20, 2018

Fixes #9446

Lets Heroes be initiated from a back swipe gesture.
Changes signature for NavigatorObserver.didStartUserGesture from

void didStartUserGesture();

to

void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute);

Measures and inserts hero flight into overlay on first frame.
Use in Cupertino nav bars.

giphy-8

Breaking signature announce: https://groups.google.com/forum/#!topic/flutter-dev/SBAlcp6W_3g

@xster xster requested review from HansMuller and Hixie October 20, 2018 00:56
@xster xster added the c: API break Backwards-incompatible API changes label Oct 22, 2018
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.

I think this is a good API change. I had a few comments about the details.


// Called by _CupertinoBackGestureDetector when a pop ("back") drag start
// gesture is detected. The returned controller handles all of the subsquent
// gesture is detected. The returned controller handles all of the subsequent
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

this.createRectTween,
this.flightShuttleBuilder,
this.placeholderBuilder,
this.transitionForUserGestures = false,
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 just bike shedding.

We call methods or callbacks that are triggered by "foo" onFoo. Since we're talking about a transition that's triggered by a user gesture here, maybe transitionOnUserGesture.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, this is sensible

final TransitionBuilder placeholderBuilder;

/// Whether to perform the hero transition if the [PageRoute] transition was
/// triggered by a user gesture such as a back swipe on iOS.
Copy link
Contributor

Choose a reason for hiding this comment

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

user gesture, such as

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks

/// left in place once the Hero shuttle has taken flight.
final TransitionBuilder placeholderBuilder;

/// Whether to perform the hero transition if the [PageRoute] transition was
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not really just a transition, it's a pop transition, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Though from this perspective (docs of Hero), the reader shouldn't really be concerned about the direction of the transition.

/// triggered by a user gesture such as a back swipe on iOS.
///
/// If [Hero]s with the same [tag] on both the from and the to routes have
/// [transitionForUserGestures] set to true, a back swipe gesture will
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 "back swipe" gesture is too specific, it's just whatever "user gesture" triggered the call to Navigator.didStartUserGesture(). It's definitely useful to tie this stuff back to the iOS back gesture, since that's the only current user case. We just don't want to imply that other use cases aren't possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. Though I'm not too sure what to put more specifically.

I think didStartUserGesture is a bit of an implementation detail (in terms of how the HeroController receives events but we can envision changing that implementation detail without having to change the 'API' in the future).

Since I can't think of a specific other use case for the trigger and it's API stable now, it's probably better to be very specific in the doc and later expand than trying to restrict the API in the future.

}

// Find the matching pairs of heros in from and to and either start or a new
// Find the matching pairs of heroes in from and to and either start or a new
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

PageRoute<dynamic> to,
Animation<double> animation,
HeroFlightDirection flightType,
bool fromGesture,
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as before about this parameter name

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

///
/// If present, the route immediately below `route` is `previousRoute`.
/// Though the gesture may not necessarily conclude at `previousRoute` if
/// canceled.
Copy link
Contributor

Choose a reason for hiding this comment

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

canceled => it is canceled.

Perhaps it's obvious but it seems like it would be worth explaining how a pop might be canceled and what that means vis didStopUserGesture().

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a bit more details.

void didReplace({ Route<dynamic> newRoute, Route<dynamic> oldRoute }) { }

/// The [Navigator]'s routes are being moved by a user gesture.
/// The [Navigator]'s route `route` is being moved by a user gesture.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should explain who needs to call this and when. From the sound of it, it's just a notification.

The doc should link to and summarize the role of didStopUserGesture as well as Hero.transitionFromUserGestures.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cross referenced didStopUserGesture.

Though this is a more generic callback API than heroes. We should probably not reference users of the API from the API.

_userGesturesInProgress += 1;
if (_userGesturesInProgress == 1) {
final Route<dynamic> route = _history.last;
final Route<dynamic> previousRoute = route.willHandlePopInternally
Copy link
Contributor

Choose a reason for hiding this comment

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

      final Route<dynamic> previousRoute = route.willHandlePopInternally || history.length < 2
        ? null
        : _history[_history.length - 2]

Copy link
Member Author

Choose a reason for hiding this comment

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

Shortened.

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

@xster xster merged commit 87ca3d5 into flutter:master Oct 26, 2018
@xster xster deleted the back-swipe-hero branch October 26, 2018 19:11
Xavjer pushed a commit to Xavjer/flutter that referenced this pull request Nov 1, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: API break Backwards-incompatible API changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create an app bar parallax transition effect for iOS

3 participants