routemaster icon indicating copy to clipboard operation
routemaster copied to clipboard

[Proposal] Support specifying page transitions on push & pop

Open RastislavMirek opened this issue 3 years ago • 5 comments

This is (also) my feedback to Routemaster 0.10.0-dev2.

Ever since I started to work with Flutter I wished there was a way to specify what the screen transition animation should be when I am calling push / pop on navigator. This is how it works in UIKit (iOS) and it is much more flexible.

In complex production apps with a lot of custom animations and flows it is not rare that a screen transition is dependent on app state that the app is in at the moment when the transition occurs. And then, the pop transition when leaving a page is dependent on something the user have done the page - therefore also known only at the time when pop is called.

Therefore, it the transitions are not known when you are building your RouteMap, they can change dynamically. Ideally, there would be a way to specify/override them in a optional parameter to RoutemasterDelegate.push() and RoutemasterDelegate.pop().

That being said, appreciate the recent addition of TransitionPage and TransitionPageBuilder. They are rather convenient. I could use TransitionPageBuilder to achieve what I want I described above but for it to work I would need to make my RouteMap dependent on app state and that feels like rather bad design. It would be cleaner and also way more convenient (producing much less boilerplate code) to have optional parameters to RoutemasterDelegate.push() and RoutemasterDelegate.pop() that could override the animation. Ideally, it would be possible to pass PageTransition subclass to these optional parameters.

Technically, this might probably be achieved by somehow wrapping the Page in TransitionPageBuilder before it is pushed to Navigator.pages if those optional parameters are present. Not sure this would work, just an idea and also details would need to be worked out.

RastislavMirek avatar Jul 24 '21 15:07 RastislavMirek

Really interesting idea, would love to provide this functionality, but... yeah... not sure how to add it 😁

I'll have a play around and see if I can come up with something that works.

I guess the ideal API would be something as simple as:

Routemaster.of(context).push('/page', transition: PageTransition.zoom);

tomgilder avatar Jul 25 '21 12:07 tomgilder

Yes, that would be perfect API. The same approach as in Swift/UIKit.

RastislavMirek avatar Jul 25 '21 13:07 RastislavMirek

And ideally pop() would also have the PageTransition transition optional parameter.

RastislavMirek avatar Jul 25 '21 14:07 RastislavMirek

API thoughts: if #96 is implemented, any state can be added to push events, so pages could provide their own state objects specifying transition types.

This allows flexibility for users to specify their own parameters with animations.

For this to be strongly-typed, it would have to use something like this:

TransitionPage.push(context, '/hello', transition: PageTransition.zoom)

That would then call:

Routemaster.of(context).push('/hello', state: TransitionPageState(transition: PageTransition.zoom))

Not wild about that API, but this does allow a lot of flexibility.

tomgilder avatar Aug 21 '21 11:08 tomgilder

This seems just fine to me.

RastislavMirek avatar Aug 21 '21 12:08 RastislavMirek