Skip to content

Commit

Permalink
stable channel support
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuqw committed Jul 15, 2021
1 parent aca3694 commit 2a96fb5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
19 changes: 11 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -40,7 +43,7 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
late final AnimationControllerSwipeHandler persistentBottomSwipeHandler;
late final AnimationController persistentBottomController;
late final SwipeRouteHandler secondSwipeHandler;
late final AnimationControllerGestureMixin horizontalSwipeHandler;
late final GestureHandler handlerComposer;
Expand All @@ -51,15 +54,16 @@ class _MyHomePageState extends State<MyHomePage> 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(
Expand Down Expand Up @@ -99,9 +103,8 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {

@override
void dispose() {
persistentBottomSwipeHandler.controller.dispose();
secondSwipeHandler.controller.dispose();
horizontalSwipeHandler.controller.dispose();
persistentBottomController.dispose();
handlerComposer.dispose();
super.dispose();
}

Expand All @@ -126,7 +129,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {

Widget buildPersistentBottom(BuildContext context) {
return SizeTransition(
sizeFactor: persistentBottomSwipeHandler.controller,
sizeFactor: persistentBottomController,
axisAlignment: -1.0,
child: Card(
margin: EdgeInsets.zero,
Expand Down
35 changes: 19 additions & 16 deletions lib/src/gesture_navigation/gesture_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ class ModalBottomSheet<T> extends StatefulWidget {
final BoxConstraints? constraints;

@override
_ModalBottomSheetState<T> createState() => _ModalBottomSheetState<T>();
ModalBottomSheetState<T> createState() => ModalBottomSheetState<T>();
}

class _ModalBottomSheetState<T> extends State<ModalBottomSheet<T>> {
class ModalBottomSheetState<T> extends State<ModalBottomSheet<T>> {
GestureModalBottomSheetRoute<T> get route => widget.route;

String _getRouteLabel(MaterialLocalizations localizations) {
Expand Down Expand Up @@ -136,20 +136,23 @@ class _ModalBottomSheetState<T> extends State<ModalBottomSheet<T>> {
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,
),
),
),
);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/gesture_navigation/navigator_gesture_recognizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ mixin NavigatorGesturesOneSequenceMixin on OneSequenceGestureRecognizer

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

class RouteVerticalDragGestureRecognizer extends VerticalDragGestureRecognizer
with NavigatorGesturesPreventingCancelingMixin, NavigatorGesturesOneSequenceMixin {
RouteVerticalDragGestureRecognizer({Object? debugOwner, Set<PointerDeviceKind>? supportedDevices})
: super(debugOwner: debugOwner, supportedDevices: supportedDevices);
RouteVerticalDragGestureRecognizer({Object? debugOwner, PointerDeviceKind? kind /*, Set<PointerDeviceKind>? supportedDevices */})
: super(debugOwner: debugOwner, kind: kind/*, supportedDevices: supportedDevices */);
}
2 changes: 1 addition & 1 deletion lib/src/gestures_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2a96fb5

Please sign in to comment.