[go: nahoru, domu]

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

Route informed animation 2 #150031

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move delegation logic to didChangeNext/didPopNext
  • Loading branch information
MitchellGoodwin committed Jun 11, 2024
commit e5b686fefe6adfff847d5ddee96451b6b5da8ca8
12 changes: 3 additions & 9 deletions packages/flutter/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final Animatable<Offset> _kBottomUpTween = Tween<Offset>(
/// * [MaterialRouteTransitionMixin], which is a mixin that provides
/// platform-appropriate transitions for a [PageRoute].
/// * [CupertinoPageRoute], which is a [PageRoute] that leverages this mixin.
mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> implements FlexibleTransitionRouteMixin<T> {
mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> {
/// Builds the primary contents of the route.
@protected
Widget buildContent(BuildContext context);
Expand Down Expand Up @@ -155,18 +155,12 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> implements FlexibleTransi
if (controller != null && controller!.isAnimating) {
return false;
}
if (nextRoute is FlexibleTransitionRouteMixin<T> && navigator != null) {
navigator!.delegateTransitionBuilder = (nextRoute as FlexibleTransitionRouteMixin<T>).delegatedTransition;
}
// Don't perform outgoing animation if the next route is a fullscreen dialog.
return nextRoute is FlexibleTransitionRouteMixin<T> || nextRoute is CupertinoRouteTransitionMixin && !nextRoute.fullscreenDialog;
}

@override
bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) {
if (previousRoute is FlexibleTransitionRouteMixin<T> && navigator != null && previousRoute.controller?.isAnimating != true) {
previousRoute.navigator!.delegateTransitionBuilder = delegatedTransition;
}
return previousRoute is FlexibleTransitionRouteMixin<T> || previousRoute is CupertinoRouteTransitionMixin && !previousRoute.fullscreenDialog;
}

Expand Down Expand Up @@ -286,7 +280,7 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> implements FlexibleTransi
/// * [CupertinoTabScaffold], for applications that have a tab bar at the
/// bottom with multiple pages.
/// * [CupertinoPage], for a [Page] version of this class.
class CupertinoPageRoute<T> extends PageRoute<T> with CupertinoRouteTransitionMixin<T> {
class CupertinoPageRoute<T> extends PageRoute<T> with CupertinoRouteTransitionMixin<T>, FlexibleTransitionRouteMixin<T> {
/// Creates a page route for use in an iOS designed app.
///
/// The [builder], [maintainState], and [fullscreenDialog] arguments must not
Expand Down Expand Up @@ -326,7 +320,7 @@ class CupertinoPageRoute<T> extends PageRoute<T> with CupertinoRouteTransitionMi
//
// This route uses the builder from the page to build its content. This ensures
// the content is up to date after page updates.
class _PageBasedCupertinoPageRoute<T> extends PageRoute<T> with CupertinoRouteTransitionMixin<T> {
class _PageBasedCupertinoPageRoute<T> extends PageRoute<T> with CupertinoRouteTransitionMixin<T>, FlexibleTransitionRouteMixin<T> {
_PageBasedCupertinoPageRoute({
required CupertinoPage<T> page,
super.allowSnapshotting = true,
Expand Down
10 changes: 1 addition & 9 deletions packages/flutter/lib/src/material/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import 'theme.dart';
/// * [MaterialRouteTransitionMixin], which provides the material transition
/// for this route.
/// * [MaterialPage], which is a [Page] of this class.
class MaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixin<T> {
class MaterialPageRoute<T> extends PageRoute<T> with MaterialRouteTransitionMixin<T>, FlexibleTransitionRouteMixin<T> {
/// Construct a MaterialPageRoute whose contents are defined by [builder].
MaterialPageRoute({
required this.builder,
Expand Down Expand Up @@ -99,7 +99,6 @@ mixin MaterialRouteTransitionMixin<T> on PageRoute<T> implements FlexibleTransit
@override
DelegatedTransitionBuilder? get delegatedTransition => _delegatedTransition;

@override
set delegatedTransition(DelegatedTransitionBuilder? newTransition) {
_delegatedTransition = newTransition;
}
Expand All @@ -109,20 +108,13 @@ mixin MaterialRouteTransitionMixin<T> on PageRoute<T> implements FlexibleTransit
if (controller != null && controller!.isAnimating) {
return false;
}
if (nextRoute is FlexibleTransitionRouteMixin<T> && navigator != null) {
navigator!.delegateTransitionBuilder = (nextRoute as FlexibleTransitionRouteMixin<T>).delegatedTransition;
}
// Don't perform outgoing animation if the next route is a fullscreen dialog.
return (nextRoute is MaterialRouteTransitionMixin && !nextRoute.fullscreenDialog)
|| (nextRoute is CupertinoRouteTransitionMixin && !nextRoute.fullscreenDialog)
|| (nextRoute is FlexibleTransitionRouteMixin<T>);
}

@override
bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) {
if (previousRoute is FlexibleTransitionRouteMixin<T> && navigator != null && previousRoute.controller?.isAnimating != true) {
previousRoute.navigator!.delegateTransitionBuilder = delegatedTransition;
}
return previousRoute is PageRoute;
}

Expand Down
21 changes: 19 additions & 2 deletions packages/flutter/lib/src/widgets/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,24 @@ abstract class PopEntry<T> {

/// Mixin for a route that can provide a delegated secondary transition to the
/// outgoing route.
abstract mixin class FlexibleTransitionRouteMixin<T> {
mixin FlexibleTransitionRouteMixin<T> on TransitionRoute<T> {
/// The delegated transition provided to the previous route.
late DelegatedTransitionBuilder? delegatedTransition;
DelegatedTransitionBuilder? get delegatedTransition;

@override
void didChangeNext(Route<dynamic>? nextRoute) {
if (nextRoute is FlexibleTransitionRouteMixin<T> && canTransitionTo(nextRoute) && navigator != null) {
debugPrint('Ping the navigator state');
navigator!.delegateTransitionBuilder = nextRoute.delegatedTransition;
}
super.didChangeNext(nextRoute);
}

@override
void didPopNext(Route<dynamic> nextRoute) {
if (nextRoute is FlexibleTransitionRouteMixin<T> && canTransitionTo(nextRoute) && navigator != null) {
navigator!.delegateTransitionBuilder = nextRoute.delegatedTransition;
}
super.didPopNext(nextRoute);
}
}