Skip to content

Commit

Permalink
fix: Fixed a bug that prevented redirects from working properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Oct 25, 2022
1 parent d17184e commit 357f7f7
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/katana_router/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ packages:
name: graphs
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.2.0"
http:
dependency: transitive
description:
Expand Down
60 changes: 42 additions & 18 deletions packages/katana_router/lib/src/app_page_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AppPageRoute<T> extends Page<T> {
required String? path,
TransitionQuery? transitionQuery,
}) {
if (transitionQuery?.transition == _TransitionQueryType.modal) {
if (transitionQuery?.transition.modal ?? false) {
return _ModalPageRoute(
key: key ?? ValueKey(uuid),
builder: builder,
Expand All @@ -66,7 +66,7 @@ class _ModalPageRoute<T> extends Page<T> implements AppPageRoute<T> {
super.key,
required this.builder,
required String? path,
TransitionQuery? transitionQuery,
this.transitionQuery,
this.isAndroidBackEnable = true,
this.transitionDuration = const Duration(milliseconds: 300),
this.opaque = false,
Expand All @@ -84,7 +84,12 @@ class _ModalPageRoute<T> extends Page<T> implements AppPageRoute<T> {
final Color? barrierColor;
final String? barrierLabel;
final bool maintainState;
final TransitionQuery? transitionQuery;

static final Animatable<Offset> _slideUpTween = Tween<Offset>(
begin: const Offset(0.0, 0.25),
end: Offset.zero,
).chain(CurveTween(curve: Curves.fastOutSlowIn));
static final Animatable<double> _scaleTween = Tween<double>(
begin: 0.25,
end: 1.0,
Expand All @@ -106,25 +111,44 @@ class _ModalPageRoute<T> extends Page<T> implements AppPageRoute<T> {
maintainState: maintainState,
fullscreenDialog: true,
pageBuilder: (context, animation, secondaryAnimation) {
return FadeTransition(
opacity: _fadeTween.animate(animation),
child: ScaleTransition(
scale: _scaleTween.animate(animation),
child: Material(
type: MaterialType.transparency,
child: SafeArea(
child: WillPopScope(
onWillPop: () async {
return isAndroidBackEnable;
},
child: Center(
child: builder(context),
switch (transitionQuery?.transition) {
case _TransitionQueryType.bottomModal:
return FadeTransition(
opacity: _fadeTween.animate(animation),
child: SlideTransition(
position: _slideUpTween.animate(animation),
child: Material(
type: MaterialType.transparency,
child: WillPopScope(
onWillPop: () async {
return isAndroidBackEnable;
},
child: Center(
child: builder(context),
),
),
),
),
),
),
);
);
default:
return FadeTransition(
opacity: _fadeTween.animate(animation),
child: ScaleTransition(
scale: _scaleTween.animate(animation),
child: Material(
type: MaterialType.transparency,
child: WillPopScope(
onWillPop: () async {
return isAndroidBackEnable;
},
child: Center(
child: builder(context),
),
),
),
),
);
}
},
);
}
Expand Down
9 changes: 6 additions & 3 deletions packages/katana_router/lib/src/app_router_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ abstract class AppRouterBase extends ChangeNotifier
late final _AppRouterConfig _config;
final List<_PageStackContainer> _pageStack = [];

BuildContext? get _context => _config.navigatorKey.currentContext;

@override
RouterDelegate<RouteQuery> get routerDelegate => _routerDelegate;
late final _AppRouterDelegate _routerDelegate;
Expand Down Expand Up @@ -183,12 +185,13 @@ abstract class AppRouterBase extends ChangeNotifier
Future<E?> push<E>(
RouteQuery routeQuery, [
TransitionQuery? transitionQuery,
]) {
]) async {
final completer = Completer<E?>();
final resolveQuery = await _redirect(_context!, routeQuery);
_pageStack.add(
_PageStackContainer<E>(
query: routeQuery,
route: routeQuery
query: resolveQuery,
route: resolveQuery
.route<E>(transitionQuery ?? _config.defaultTransitionQuery),
completer: completer,
),
Expand Down
18 changes: 14 additions & 4 deletions packages/katana_router/lib/src/transition_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,25 @@ class TransitionQuery {
static TransitionQuery get fade =>
const TransitionQuery._(transition: _TransitionQueryType.fade);

/// [TransitionQuery] that performs modal transitions.
/// [TransitionQuery] that performs a modal transition from the middle.
///
/// The back page will be visible.
///
/// モーダルのトランジションを行なう[TransitionQuery]
/// 真ん中からのモーダルのトランジションを行なう[TransitionQuery]
///
/// 裏のページが見えるようになります。
static TransitionQuery get modal =>
const TransitionQuery._(transition: _TransitionQueryType.modal);
static TransitionQuery get centerModal =>
const TransitionQuery._(transition: _TransitionQueryType.centerModal);

/// [TransitionQuery] to perform modal transitions from below.
///
/// The back page will be visible.
///
/// 下からのモーダルのトランジションを行なう[TransitionQuery]
///
/// 裏のページが見えるようになります。
static TransitionQuery get bottomModal =>
const TransitionQuery._(transition: _TransitionQueryType.bottomModal);

@override
bool operator ==(Object other) => hashCode == other.hashCode;
Expand Down
33 changes: 26 additions & 7 deletions packages/katana_router/lib/src/transition_query_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,48 @@ enum _TransitionQueryType {
/// Default transitions.
///
/// デフォルトのトランジション。
initial,
initial(modal: false),

/// No transitions.
///
/// トランジションしない。
none,
none(modal: false),

/// Full screen transition.
///
/// フルスクリーントランジション。
fullscreen,
fullscreen(modal: false),

/// Fade transitions.
///
/// フェードトランジション。
fade,
fade(modal: false),

/// Modal Transitions.
/// Modal transition from the middle.
///
/// The back page will be visible.
///
/// モーダルトランジション
/// 真ん中からのモーダルトランジション
///
/// 裏のページが見えるようになります。
modal;
centerModal(modal: true),

/// Modal transitions from below.
///
/// The back page will be visible.
///
/// 下からのモーダルトランジション。
///
/// 裏のページが見えるようになります。
bottomModal(modal: true);

/// Defines how the page transitions.
///
/// ページのトランジション方法を定義します。
const _TransitionQueryType({required this.modal});

/// True when using a modal.
///
/// モーダルを利用する場合True.
final bool modal;
}

0 comments on commit 357f7f7

Please sign in to comment.