improve back/forward navigation
This commit is contained in:
+18
-28
@@ -56,7 +56,6 @@ import 'package:weblibre/presentation/hooks/menu_controller.dart';
|
|||||||
import 'package:weblibre/presentation/icons/tor_icons.dart';
|
import 'package:weblibre/presentation/icons/tor_icons.dart';
|
||||||
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
|
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
|
||||||
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
import 'package:weblibre/presentation/widgets/url_icon.dart';
|
||||||
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
|
|
||||||
|
|
||||||
class BrowserTopAppBar extends HookConsumerWidget {
|
class BrowserTopAppBar extends HookConsumerWidget {
|
||||||
final bool showMainToolbar;
|
final bool showMainToolbar;
|
||||||
@@ -400,7 +399,8 @@ class ContextualToolbar extends HookConsumerWidget {
|
|||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
if (tabState?.historyState.canGoBack == true)
|
if (tabState?.historyState.canGoBack == true ||
|
||||||
|
tabState?.isLoading == true)
|
||||||
NavigateBackButton(
|
NavigateBackButton(
|
||||||
selectedTabId: selectedTabId,
|
selectedTabId: selectedTabId,
|
||||||
isLoading: tabState?.isLoading ?? false,
|
isLoading: tabState?.isLoading ?? false,
|
||||||
@@ -829,30 +829,11 @@ class NavigationMenuButton extends HookConsumerWidget {
|
|||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: (history?.canGoBack == true || isLoading)
|
child: NavigateBackButton(
|
||||||
? NavigateBackButton(
|
|
||||||
selectedTabId: selectedTabId,
|
selectedTabId: selectedTabId,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
menuControllerToClose: hamburgerMenuController,
|
menuControllerToClose: hamburgerMenuController,
|
||||||
)
|
canGoBack: history?.canGoBack == true,
|
||||||
: IconButton(
|
|
||||||
onPressed: () async {
|
|
||||||
await ref
|
|
||||||
.read(tabRepositoryProvider.notifier)
|
|
||||||
.closeTab(selectedTabId!);
|
|
||||||
|
|
||||||
hamburgerMenuController.close();
|
|
||||||
|
|
||||||
if (context.mounted) {
|
|
||||||
ui_helper.showTabUndoClose(
|
|
||||||
context,
|
|
||||||
ref
|
|
||||||
.read(tabRepositoryProvider.notifier)
|
|
||||||
.undoClose,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.close),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 48, child: VerticalDivider()),
|
const SizedBox(height: 48, child: VerticalDivider()),
|
||||||
@@ -860,6 +841,7 @@ class NavigationMenuButton extends HookConsumerWidget {
|
|||||||
child: NavigateForwardButton(
|
child: NavigateForwardButton(
|
||||||
selectedTabId: selectedTabId,
|
selectedTabId: selectedTabId,
|
||||||
menuControllerToClose: hamburgerMenuController,
|
menuControllerToClose: hamburgerMenuController,
|
||||||
|
canGoForward: history?.canGoForward == true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -876,22 +858,26 @@ class NavigateForwardButton extends HookConsumerWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.selectedTabId,
|
required this.selectedTabId,
|
||||||
this.menuControllerToClose,
|
this.menuControllerToClose,
|
||||||
|
this.canGoForward = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? selectedTabId;
|
final String? selectedTabId;
|
||||||
final MenuController? menuControllerToClose;
|
final MenuController? menuControllerToClose;
|
||||||
|
final bool canGoForward;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
onPressed: () async {
|
onPressed: canGoForward
|
||||||
|
? () async {
|
||||||
final controller = ref.read(
|
final controller = ref.read(
|
||||||
tabSessionProvider(tabId: selectedTabId).notifier,
|
tabSessionProvider(tabId: selectedTabId).notifier,
|
||||||
);
|
);
|
||||||
|
|
||||||
await controller.goForward();
|
await controller.goForward();
|
||||||
menuControllerToClose?.close();
|
menuControllerToClose?.close();
|
||||||
},
|
}
|
||||||
|
: null,
|
||||||
icon: const Icon(Icons.arrow_forward),
|
icon: const Icon(Icons.arrow_forward),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -903,16 +889,19 @@ class NavigateBackButton extends HookConsumerWidget {
|
|||||||
required this.selectedTabId,
|
required this.selectedTabId,
|
||||||
required this.isLoading,
|
required this.isLoading,
|
||||||
this.menuControllerToClose,
|
this.menuControllerToClose,
|
||||||
|
this.canGoBack = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? selectedTabId;
|
final String? selectedTabId;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final MenuController? menuControllerToClose;
|
final MenuController? menuControllerToClose;
|
||||||
|
final bool canGoBack;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
onPressed: () async {
|
onPressed: (canGoBack || isLoading)
|
||||||
|
? () async {
|
||||||
final controller = ref.read(
|
final controller = ref.read(
|
||||||
tabSessionProvider(tabId: selectedTabId).notifier,
|
tabSessionProvider(tabId: selectedTabId).notifier,
|
||||||
);
|
);
|
||||||
@@ -934,8 +923,9 @@ class NavigateBackButton extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menuControllerToClose?.close();
|
menuControllerToClose?.close();
|
||||||
},
|
}
|
||||||
icon: const Icon(Icons.arrow_back),
|
: null,
|
||||||
|
icon: isLoading ? const Icon(Icons.close) : const Icon(Icons.arrow_back),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user