Skip to content

Conversation

@HansMuller
Copy link
Contributor

@HansMuller HansMuller commented Sep 12, 2018

MaterialPageRoute transitions are now defined by the Theme. Added (optional) support for Android P style page transitions.

The default MaterialPageRoute transitions have not changed: the horizontal CuperitinoPageTransition is still used when the target platform is iOS and the fading upwards transition is used for all other target platforms.

Added a ThemeData.pageTransitionsTheme which provides the default implementation of MaterialPageRoute.buildTransitions per target platform. Subclasses of PageTransitionsBuilder define buildTransitions methods.

Three PageTransitionsBuilder subclasses are provided: FadeUpwardsTransitionsBuilder, CupertinoPageTransitionsBuilder, OpenUpwardsPageTransitionsBuilder.

By default PageTransitionsTheme only includes FadeUpwardsPageTransitionsBuilder, and CupertinoPageTransitionsBuilder.

To use the new Android P style page transition when the target platform is Android, include OpenUpwardsPageTransitionsBuilder in the Theme's pageTransitionsTheme. For example:

new MaterialApp(
  theme: new ThemeData(
    pageTransitionsTheme: const PageTransitionsTheme(
      builders: <TargetPlatform, PageTransitionsBuilder>{
        TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
        TargetPlatform.android: OpenUpwardsPageTransitionsBuilder(),
      },
    ),
  ),
  ...
)

Two of the CupertinoPageRoute methods that had been used to enable building a MaterialPageRoute that used a "host" CupertinoPageRoute's buildTransitions() method have been removed or changed:

PageRoute<T> get hostRoute;  // also removed the constructor parameter
bool get popGestureInProgress;

The last method was replaced by a static method that reports the same value for any route that's using a Cupertino transition:

  static bool isPopGestureInProgress(PageRoute route)

These are backwards incompatible changes. However it seems unlikely that any existing apps depended on them.

Copy link
Contributor

Choose a reason for hiding this comment

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

please run flutter analyze --dartdocs to catch places where we need to add docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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 technically a breaking change so we should definitely mention it on flutter-dev, but I find it hard to imagine that it's going to break any actual apps since it doesn't really do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sent a warning about this change to flutter-dev, subject "Proposed changes to the CupertinoPageRoute class", on 9/10. Will definitely send a definitive message when this PR lands.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/ - /, /

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: (not new, but since you're here) return after else

Copy link
Contributor Author

@HansMuller HansMuller Sep 14, 2018

Choose a reason for hiding this comment

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

I assumed that what's needed here is:

assert(false);
return null;

At the end of the method. The analyzer reports that as dead code. What did you want here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just meant that you could remove the else { part and just have that be at the top level of the method.

Copy link
Contributor

Choose a reason for hiding this comment

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

docs need updating a bit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

can you pass transformHitTests: false to this widget and remove the TODO while you're here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I undid this change. It cause a few tests to fail and in the interest of limiting the scope of this PR, I've put the TODO back for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need the clip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. The new page is pinned to the bottom and the clip exposes more and more of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's pinned to the bottom of the screen then we don't need to clip it, since it's overflowing the screen where the physical device will handle clipping for us, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other than a tiny translation, the new page appears exactly where it will end up (it doesn't overflow). The clip is like a vertical curtain that's pulled upwards: so the bottom of the page is exposed first.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would call this (and the previous one) something more descriptive.

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 avoid using underscores for argument names, it just makes people confused when reading the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about. Plus now I'm using the parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can make this a child of the outer AnimatedBuilder to avoid rebuilding the inner one each time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be in the cupertino library?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, i see, this is sort of specific to material...

Copy link
Contributor

Choose a reason for hiding this comment

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

this seems overly general when the reality is we just care about iOS vs anything else.

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 care about more than that though? I don't really understand why the PageTransitionsBuilders have explicit platforms, and why the general one is different than the mountain view one.

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 PR enables one to add an Android-specific transition, the MountainViewPageTransition. I've enabled configuring the default transition for any platform, which is indeed over achievement, however I think it's a useful point for customization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default generic transition is identical to the one we use on Android/Fuschia today. It's no longer part of the Material Spec and it's very different from the default transition on the latest Android (P).

Copy link
Contributor

Choose a reason for hiding this comment

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

is there much benefit to having the _GenericPageTransition widget rather than just inlining its build method here?

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 way you can substitute your own generic (not target platform specific) page transition.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how it helps with this? The widgets are private, so the effect seems to be identical, from a black-box perspective, as having the widgets inlined.

Copy link
Contributor

Choose a reason for hiding this comment

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

boy is this out of hand

Copy link
Contributor

Choose a reason for hiding this comment

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

please make sure these are in the exact same order as in operator == and in the constructor and in the order of fields in the class

Copy link
Contributor

Choose a reason for hiding this comment

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

and in the lerps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed up the order of everything and added some missing (yikes) arguments to hashValues/==.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite sure what "per [TargetPlatform]" means here. Maybe elaborate a bit for these docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@HansMuller HansMuller force-pushed the page_transition_theme branch from 8f7f512 to a7adfaf Compare September 14, 2018 18:18
Copy link
Contributor

Choose a reason for hiding this comment

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

can we keep this one around for back-compat? It can be implemented just like popGestureEnabled, using the statics and this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Hixie
Copy link
Contributor

Hixie commented Sep 19, 2018

I have to be honest the whole thing with the transitions having platforms feels very strange to me. I don't see why the opening up transition has any affinity to Android, and why the sliding one doesn't. I understand why the Cupertino one does, but only insofar as we have to use that one to enable the back gesture. Why can't the Theme declare what the right transition is based on the platform, rather than have the transitions think about the issue? (Notwithstanding that once you've picked a transition, it shouldn't change until it's over, even if you change platform, so that we don't crash when switching out of iOS mode with an active back gesture.)

@HansMuller HansMuller force-pushed the page_transition_theme branch from a1cce5c to c8f8105 Compare September 19, 2018 23:23
@HansMuller
Copy link
Contributor Author

PageTransitionsBuilders no longer have a platform. The PageTransitionsTheme now has a TargetPlatform => PageTransitionsBuilder map.

@HansMuller HansMuller force-pushed the page_transition_theme branch from c8f8105 to 7b2f3ae Compare September 24, 2018 17:03
Copy link
Contributor

Choose a reason for hiding this comment

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

this one should probably transform if it's being driven by the user and not otherwise... :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

still mentions platform

Copy link
Contributor

Choose a reason for hiding this comment

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

[] around the class name

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

this paragraph is obsolete

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use the iOS platform to look it up in the map, or should it forcibly use the cupertino transition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to continue using whatever transition was defined for iOS. That's CupertinoTransition by default of course.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe ?? const FadeUpwardsPageTransitionsBuilder() ?

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 method is just for the operator == definition. I added an explanatory comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

might be good to precache this on creation, since i imagine (hope?) that this class will be compared more often than created...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The operator == method only uses this value when the lists of builders aren't identical. Hopefully that's a rarity. If not I'll add some caching.

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 just hand in _defaultBuilders directly instead of the dance here with defaultTheme, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done.

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 this can be made const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point.

@Hixie
Copy link
Contributor

Hixie commented Sep 24, 2018

LGTM

@HansMuller HansMuller force-pushed the page_transition_theme branch 2 times, most recently from dc5e37c to 7b9152f Compare September 24, 2018 23:03
Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

LGTM modulo the 'Open' name. I wish we can call it something more visually descriptive.

Copy link
Member

Choose a reason for hiding this comment

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

Needs a small tweak. As-is, it reads a bit as if this class itself doesn't use this.

Copy link
Member

Choose a reason for hiding this comment

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

For future readers, describe which Android versions this corresponds too.

Copy link
Member

Choose a reason for hiding this comment

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

Describe the motion briefly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is // internal documentation, I included the motion descriptions with the Tweens that define them.

The corresponding (public) PageTransitionBuilder does explain the motion in its class dartdoc.

Copy link
Member

Choose a reason for hiding this comment

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

'Open' isn't very visually descriptive. Perhaps 'Parallax' or 'Reveal'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like calling this transition OpenUpwards. The new page doesn't really move (not much), but we "open" a view of it that expands upwards.

Copy link
Member

Choose a reason for hiding this comment

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

Chatted a bit offline. Conceptually, this sounds a bit suspicious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've reversed the direction, which undid a last-minute and ill considered change.

Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Member

Choose a reason for hiding this comment

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

No change needed, though I'm a bit surprised we don't have a FractionalClip or something.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just create this once since you use it 3 times

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

Copy link
Member

Choose a reason for hiding this comment

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

Add a small commentary for when users should choose to use this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment I don't have anything to add. It's the default, same as it ever was.

It was based on video content from the original Material spec and it's common in Material Android apps before version P.

Copy link
Member

Choose a reason for hiding this comment

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

Open still doesn't feel descriptive. I'm sure there are prior-art from things like PowerPoint or Adobe Premier that we can re-use.

Copy link
Member

Choose a reason for hiding this comment

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

So PowerPoint calls it 'Wipe' or 'Cover' and Apple Keynote calls it 'Reveal'. I think any of them are an improvement on 'Open'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they're all OK, and I'm happy with "open".

@HansMuller HansMuller force-pushed the page_transition_theme branch from a766aeb to 0d98dcc Compare September 25, 2018 00:36
@HansMuller HansMuller merged commit 582f35d into flutter:master Sep 25, 2018
@HansMuller HansMuller deleted the page_transition_theme branch September 25, 2018 17:56
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants