Skip to content

Commit

Permalink
new material adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
JesperBllnbm committed May 18, 2023
1 parent db3ad69 commit 23c5878
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 66 deletions.
122 changes: 64 additions & 58 deletions lib/src/gesture_navigation/gesture_route_transition_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ mixin GestureRouteTransitionMixin<T> on ModalRoute<T> {

GestureHandler get gestureHandler => gestureDelegate.gestureHandler;

GestureHandler? get barrierGestureHandler => gestureDelegate.barrierGestureHandler;
GestureHandler? get barrierGestureHandler =>
gestureDelegate.barrierGestureHandler;

@override
AnimationController createAnimationController() => gestureDelegate.createAnimationController();
AnimationController createAnimationController() =>
gestureDelegate.createAnimationController();

@override
void install() {
Expand All @@ -35,14 +37,16 @@ mixin GestureRouteTransitionMixin<T> on ModalRoute<T> {
}

@override
Widget buildTransitions(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
final transitionChild = buildPageTransitions(context, animation, secondaryAnimation, child);
return buildGestureListener(context, animation, secondaryAnimation, transitionChild);
Widget buildTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
final transitionChild =
buildPageTransitions(context, animation, secondaryAnimation, child);
return buildGestureListener(
context, animation, secondaryAnimation, transitionChild);
}

Widget buildGestureListener(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
Widget buildGestureListener(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return GestureListener(
handler: gestureDelegate.gestureHandler,
behavior: gestureBehavior,
Expand All @@ -51,8 +55,8 @@ mixin GestureRouteTransitionMixin<T> on ModalRoute<T> {
);
}

Widget buildPageTransitions(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child);
Widget buildPageTransitions(BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child);

@override
void changedInternalState() {
Expand All @@ -71,7 +75,7 @@ mixin GestureRouteTransitionMixin<T> on ModalRoute<T> {

Widget buildGestureModalBarrier(BuildContext context) {
final gestureHandler = barrierGestureHandler;
Widget barrier = buildModalBarrier(context, barrierDismissible && gestureHandler == null);
Widget barrier = buildModalBarrier();
if (gestureHandler != null) {
barrier = Stack(
children: [
Expand All @@ -88,57 +92,59 @@ mixin GestureRouteTransitionMixin<T> on ModalRoute<T> {
return barrier;
}

Widget buildModalBarrier(BuildContext context, bool barrierDismissible) {
Widget barrier;
if (barrierColor != null && barrierColor!.alpha != 0 && !offstage) {
// changedInternalState is called if barrierColor or offstage updates
assert(barrierColor != barrierColor!.withOpacity(0.0));
final Animation<Color?> color = animation!.drive(
ColorTween(
begin: barrierColor!.withOpacity(0.0),
end: barrierColor, // changedInternalState is called if barrierColor updates
).chain(CurveTween(curve: barrierCurve)), // changedInternalState is called if barrierCurve updates
);
barrier = AnimatedModalBarrier(
color: color,
dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates
semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates
barrierSemanticsDismissible: semanticsDismissible,
);
} else {
barrier = ModalBarrier(
dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates
semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates
barrierSemanticsDismissible: semanticsDismissible,
);
}
if (filter != null) {
barrier = BackdropFilter(
filter: filter!,
child: barrier,
);
}
barrier = IgnorePointer(
ignoring: animation!.status ==
AnimationStatus.reverse || // changedInternalState is called when animation.status updates
animation!.status == AnimationStatus.dismissed, // dismissed is possible when doing a manual pop gesture
child: barrier,
);
if (semanticsDismissible && this.barrierDismissible) {
// To be sorted after the _modalScope.
barrier = Semantics(
sortKey: const OrdinalSortKey(1.0),
child: barrier,
);
}
return barrier;
}
// Widget buildModalBarrier(BuildContext context, bool barrierDismissible) {
// Widget barrier;
// if (barrierColor != null && barrierColor!.alpha != 0 && !offstage) {
// // changedInternalState is called if barrierColor or offstage updates
// assert(barrierColor != barrierColor!.withOpacity(0.0));
// final Animation<Color?> color = animation!.drive(
// ColorTween(
// begin: barrierColor!.withOpacity(0.0),
// end: barrierColor, // changedInternalState is called if barrierColor updates
// ).chain(CurveTween(curve: barrierCurve)), // changedInternalState is called if barrierCurve updates
// );
// barrier = AnimatedModalBarrier(
// color: color,
// dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates
// semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates
// barrierSemanticsDismissible: semanticsDismissible,
// );
// } else {
// barrier = ModalBarrier(
// dismissible: barrierDismissible, // changedInternalState is called if barrierDismissible updates
// semanticsLabel: barrierLabel, // changedInternalState is called if barrierLabel updates
// barrierSemanticsDismissible: semanticsDismissible,
// );
// }
// if (filter != null) {
// barrier = BackdropFilter(
// filter: filter!,
// child: barrier,
// );
// }
// barrier = IgnorePointer(
// ignoring: animation!.status ==
// AnimationStatus.reverse || // changedInternalState is called when animation.status updates
// animation!.status == AnimationStatus.dismissed, // dismissed is possible when doing a manual pop gesture
// child: barrier,
// );
// if (semanticsDismissible && this.barrierDismissible) {
// // To be sorted after the _modalScope.
// barrier = Semantics(
// sortKey: const OrdinalSortKey(1.0),
// child: barrier,
// );
// }
// return barrier;
// }

@override
Iterable<OverlayEntry> createOverlayEntries() {
final modalOverlays = List<OverlayEntry>.from(super.createOverlayEntries(), growable: false);
final modalOverlays =
List<OverlayEntry>.from(super.createOverlayEntries(), growable: false);
if (barrierGestureHandler != null) {
_modalBarrier = OverlayEntry(builder: (context) => buildGestureModalBarrier(context));
_modalBarrier =
OverlayEntry(builder: (context) => buildGestureModalBarrier(context));
modalOverlays[0] = _modalBarrier!;
}
return modalOverlays;
Expand Down
33 changes: 25 additions & 8 deletions lib/src/gesture_navigation/navigator_gesture_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import '../gestures_binding.dart';

mixin NavigatorGesturesPreventingCancelingMixin on GestureRecognizer {
static NavigatorGesturesBinding? getGestureBinding() {
if (GestureBinding.instance is NavigatorGesturesBinding) return GestureBinding.instance as NavigatorGesturesBinding;
if (GestureBinding.instance is NavigatorGesturesBinding) {
return GestureBinding.instance as NavigatorGesturesBinding;
}
return null;
}

Expand Down Expand Up @@ -33,14 +35,29 @@ mixin NavigatorGesturesOneSequenceMixin on OneSequenceGestureRecognizer
}
}

class RouteHorizontalDragGestureRecognizer extends HorizontalDragGestureRecognizer
with NavigatorGesturesPreventingCancelingMixin, NavigatorGesturesOneSequenceMixin {
RouteHorizontalDragGestureRecognizer({Object? debugOwner, PointerDeviceKind? kind /*, Set<PointerDeviceKind>? supportedDevices */})
: super(debugOwner: debugOwner, kind: kind/*, supportedDevices: supportedDevices */);
class RouteHorizontalDragGestureRecognizer
extends HorizontalDragGestureRecognizer
with
NavigatorGesturesPreventingCancelingMixin,
NavigatorGesturesOneSequenceMixin {
RouteHorizontalDragGestureRecognizer(
{Object? debugOwner,
PointerDeviceKind? kind /*, Set<PointerDeviceKind>? supportedDevices */
})
: super(
debugOwner: debugOwner, /*, supportedDevices: supportedDevices */
);
}

class RouteVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer
with NavigatorGesturesPreventingCancelingMixin, NavigatorGesturesOneSequenceMixin {
RouteVerticalDragGestureRecognizer({Object? debugOwner, PointerDeviceKind? kind /*, Set<PointerDeviceKind>? supportedDevices */})
: super(debugOwner: debugOwner, kind: kind/*, supportedDevices: supportedDevices */);
with
NavigatorGesturesPreventingCancelingMixin,
NavigatorGesturesOneSequenceMixin {
RouteVerticalDragGestureRecognizer(
{Object? debugOwner,
PointerDeviceKind? kind /*, Set<PointerDeviceKind>? supportedDevices */
})
: super(
debugOwner: debugOwner, /*, supportedDevices: supportedDevices */
);
}

0 comments on commit 23c5878

Please sign in to comment.