From 6830d94bacc4cebdc0e038f5450632f5e13ec4b3 Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Fri, 14 Mar 2025 00:47:15 +0100 Subject: [PATCH] fix drag distance --- .../widgets/browser_modules/app_bar_title.dart | 3 +++ .../widgets/browser_modules/bottom_app_bar.dart | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/app_bar_title.dart b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/app_bar_title.dart index 9981ba4a..53e7cc45 100644 --- a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/app_bar_title.dart +++ b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/app_bar_title.dart @@ -10,12 +10,14 @@ class AppBarTitle extends StatelessWidget { final VoidCallback? onTap; final VoidCallback? onLongPress; + final GestureDragStartCallback? onHorizontalDragStart; final GestureDragEndCallback? onHorizontalDragEnd; const AppBarTitle({ required this.tab, this.onTap, this.onLongPress, + this.onHorizontalDragStart, this.onHorizontalDragEnd, super.key, }); @@ -46,6 +48,7 @@ class AppBarTitle extends StatelessWidget { return GestureDetector( onTap: onTap, onLongPress: onLongPress, + onHorizontalDragStart: onHorizontalDragStart, onHorizontalDragEnd: onHorizontalDragEnd, child: Row( children: [ diff --git a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart index fe287ef1..56f09985 100644 --- a/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart +++ b/app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart @@ -1,4 +1,5 @@ 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_mozilla_components/flutter_mozilla_components.dart'; import 'package:go_router/go_router.dart'; @@ -50,6 +51,8 @@ class BrowserBottomAppBar extends HookConsumerWidget { builder: (context, ref, child) { final tabState = ref.watch(tabStateProvider(selectedTabId)); + final dragStartPosition = useRef(Offset.zero); + return (tabState != null) ? AppBarTitle( tab: tabState, @@ -75,8 +78,15 @@ class BrowserBottomAppBar extends HookConsumerWidget { .loadUrl(url: newUrl); } }, + onHorizontalDragStart: (details) { + dragStartPosition.value = details.globalPosition; + }, onHorizontalDragEnd: (details) async { - if (details.localPosition.dx > 150) { + final distance = + dragStartPosition.value - + details.globalPosition; + + if (distance.dx.abs() > 50) { await ref .read(tabRepositoryProvider.notifier) .selectPreviousTab();