From 2a96fb56272a1214f3fbcfba87edb032e90d7d46 Mon Sep 17 00:00:00 2001 From: w Date: Thu, 15 Jul 2021 00:16:10 +0500 Subject: [PATCH] stable channel support --- example/lib/main.dart | 19 +++++----- .../gesture_bottom_sheet.dart | 35 ++++++++++--------- .../navigator_gesture_recognizer.dart | 8 ++--- lib/src/gestures_binding.dart | 2 +- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 1765611..70af0f5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -3,7 +3,10 @@ import 'package:flutter/material.dart'; import 'package:gesture_handlers/gesture_handlers.dart'; void main() { + // debugPrintRecognizerCallbacksTrace = true; // debugPrintPreventCancelPointer = true; + + /// [GestureBinding] implementation for prevent route [GestureHandler] active pointers canceling by [NavigatorState]. NavigatorGesturesFlutterBinding.ensureInitialized(); runApp(const MyApp()); } @@ -40,7 +43,7 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State with TickerProviderStateMixin { - late final AnimationControllerSwipeHandler persistentBottomSwipeHandler; + late final AnimationController persistentBottomController; late final SwipeRouteHandler secondSwipeHandler; late final AnimationControllerGestureMixin horizontalSwipeHandler; late final GestureHandler handlerComposer; @@ -51,15 +54,16 @@ class _MyHomePageState extends State with TickerProviderStateMixin { double get bottomSheetHeight => 0.8 * size.height; - bool get isPersistentBottomOpened => persistentBottomSwipeHandler.controller.value.round() > 0; + bool get isPersistentBottomOpened => persistentBottomController.value.round() > 0; @override void initState() { super.initState(); - persistentBottomSwipeHandler = AnimationControllerSwipeHandler( + persistentBottomController = AnimationController(duration: const Duration(milliseconds: 300), vsync: this); + final persistentBottomSwipeHandler = AnimationControllerSwipeHandler( direction: DragDirection.vertical, reverse: true, - controller: AnimationController(duration: const Duration(milliseconds: 300), vsync: this), + controller: persistentBottomController, getChildSize: () => persistentBottomHeight, ); secondSwipeHandler = SwipeRouteHandler( @@ -99,9 +103,8 @@ class _MyHomePageState extends State with TickerProviderStateMixin { @override void dispose() { - persistentBottomSwipeHandler.controller.dispose(); - secondSwipeHandler.controller.dispose(); - horizontalSwipeHandler.controller.dispose(); + persistentBottomController.dispose(); + handlerComposer.dispose(); super.dispose(); } @@ -126,7 +129,7 @@ class _MyHomePageState extends State with TickerProviderStateMixin { Widget buildPersistentBottom(BuildContext context) { return SizeTransition( - sizeFactor: persistentBottomSwipeHandler.controller, + sizeFactor: persistentBottomController, axisAlignment: -1.0, child: Card( margin: EdgeInsets.zero, diff --git a/lib/src/gesture_navigation/gesture_bottom_sheet.dart b/lib/src/gesture_navigation/gesture_bottom_sheet.dart index 75dd6ed..2b5b50a 100644 --- a/lib/src/gesture_navigation/gesture_bottom_sheet.dart +++ b/lib/src/gesture_navigation/gesture_bottom_sheet.dart @@ -104,10 +104,10 @@ class ModalBottomSheet extends StatefulWidget { final BoxConstraints? constraints; @override - _ModalBottomSheetState createState() => _ModalBottomSheetState(); + ModalBottomSheetState createState() => ModalBottomSheetState(); } -class _ModalBottomSheetState extends State> { +class ModalBottomSheetState extends State> { GestureModalBottomSheetRoute get route => widget.route; String _getRouteLabel(MaterialLocalizations localizations) { @@ -136,20 +136,23 @@ class _ModalBottomSheetState extends State> { label: routeLabel, explicitChildNodes: true, child: ClipRect( - child: BottomSheet( - // animationController: route.controller, - onClosing: () { - if (route.isCurrent) { - Navigator.pop(context); - } - }, - builder: route.builder, - backgroundColor: widget.backgroundColor, - elevation: widget.elevation, - shape: widget.shape, - clipBehavior: widget.clipBehavior, - constraints: widget.constraints, - enableDrag: false, + child: Container( + constraints: widget.constraints, // TODO: remove & use BottomSheet constraints + child: BottomSheet( + // animationController: route.controller, + onClosing: () { + if (route.isCurrent) { + Navigator.pop(context); + } + }, + builder: route.builder, + backgroundColor: widget.backgroundColor, + elevation: widget.elevation, + shape: widget.shape, + clipBehavior: widget.clipBehavior, + // constraints: widget.constraints, + enableDrag: false, + ), ), ), ); diff --git a/lib/src/gesture_navigation/navigator_gesture_recognizer.dart b/lib/src/gesture_navigation/navigator_gesture_recognizer.dart index eb90715..af06b19 100644 --- a/lib/src/gesture_navigation/navigator_gesture_recognizer.dart +++ b/lib/src/gesture_navigation/navigator_gesture_recognizer.dart @@ -35,12 +35,12 @@ mixin NavigatorGesturesOneSequenceMixin on OneSequenceGestureRecognizer class RouteHorizontalDragGestureRecognizer extends HorizontalDragGestureRecognizer with NavigatorGesturesPreventingCancelingMixin, NavigatorGesturesOneSequenceMixin { - RouteHorizontalDragGestureRecognizer({Object? debugOwner, Set? supportedDevices}) - : super(debugOwner: debugOwner, supportedDevices: supportedDevices); + RouteHorizontalDragGestureRecognizer({Object? debugOwner, PointerDeviceKind? kind /*, Set? supportedDevices */}) + : super(debugOwner: debugOwner, kind: kind/*, supportedDevices: supportedDevices */); } class RouteVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer with NavigatorGesturesPreventingCancelingMixin, NavigatorGesturesOneSequenceMixin { - RouteVerticalDragGestureRecognizer({Object? debugOwner, Set? supportedDevices}) - : super(debugOwner: debugOwner, supportedDevices: supportedDevices); + RouteVerticalDragGestureRecognizer({Object? debugOwner, PointerDeviceKind? kind /*, Set? supportedDevices */}) + : super(debugOwner: debugOwner, kind: kind/*, supportedDevices: supportedDevices */); } diff --git a/lib/src/gestures_binding.dart b/lib/src/gestures_binding.dart index cc03381..86a9199 100644 --- a/lib/src/gestures_binding.dart +++ b/lib/src/gestures_binding.dart @@ -6,7 +6,7 @@ import 'package:flutter/widgets.dart'; /// This flag only has an effect in debug mode. bool debugPrintPreventCancelPointer = false; -/// [GestureBinding] implementation for prevent [RouteGestureHandler] active pointers canceling by [NavigatorState]. +/// [GestureBinding] implementation for prevent route [GestureHandler] active pointers canceling by [NavigatorState]. /// /// [NavigatorState] cancel active pointers after navigation. mixin NavigatorGesturesBinding on GestureBinding {