fix drag distance

This commit is contained in:
Fabian Freund
2025-03-14 00:47:15 +01:00
parent 85da553c01
commit 6830d94bac
2 changed files with 14 additions and 1 deletions
@@ -10,12 +10,14 @@ class AppBarTitle extends StatelessWidget {
final VoidCallback? onTap; final VoidCallback? onTap;
final VoidCallback? onLongPress; final VoidCallback? onLongPress;
final GestureDragStartCallback? onHorizontalDragStart;
final GestureDragEndCallback? onHorizontalDragEnd; final GestureDragEndCallback? onHorizontalDragEnd;
const AppBarTitle({ const AppBarTitle({
required this.tab, required this.tab,
this.onTap, this.onTap,
this.onLongPress, this.onLongPress,
this.onHorizontalDragStart,
this.onHorizontalDragEnd, this.onHorizontalDragEnd,
super.key, super.key,
}); });
@@ -46,6 +48,7 @@ class AppBarTitle extends StatelessWidget {
return GestureDetector( return GestureDetector(
onTap: onTap, onTap: onTap,
onLongPress: onLongPress, onLongPress: onLongPress,
onHorizontalDragStart: onHorizontalDragStart,
onHorizontalDragEnd: onHorizontalDragEnd, onHorizontalDragEnd: onHorizontalDragEnd,
child: Row( child: Row(
children: [ children: [
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart'; import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart'; import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
@@ -50,6 +51,8 @@ class BrowserBottomAppBar extends HookConsumerWidget {
builder: (context, ref, child) { builder: (context, ref, child) {
final tabState = ref.watch(tabStateProvider(selectedTabId)); final tabState = ref.watch(tabStateProvider(selectedTabId));
final dragStartPosition = useRef(Offset.zero);
return (tabState != null) return (tabState != null)
? AppBarTitle( ? AppBarTitle(
tab: tabState, tab: tabState,
@@ -75,8 +78,15 @@ class BrowserBottomAppBar extends HookConsumerWidget {
.loadUrl(url: newUrl); .loadUrl(url: newUrl);
} }
}, },
onHorizontalDragStart: (details) {
dragStartPosition.value = details.globalPosition;
},
onHorizontalDragEnd: (details) async { onHorizontalDragEnd: (details) async {
if (details.localPosition.dx > 150) { final distance =
dragStartPosition.value -
details.globalPosition;
if (distance.dx.abs() > 50) {
await ref await ref
.read(tabRepositoryProvider.notifier) .read(tabRepositoryProvider.notifier)
.selectPreviousTab(); .selectPreviousTab();