improve back/forward navigation
This commit is contained in:
+45
-55
@@ -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,37 +829,19 @@ 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()),
|
||||||
Expanded(
|
Expanded(
|
||||||
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
|
||||||
final controller = ref.read(
|
? () async {
|
||||||
tabSessionProvider(tabId: selectedTabId).notifier,
|
final controller = ref.read(
|
||||||
);
|
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,39 +889,43 @@ 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)
|
||||||
final controller = ref.read(
|
? () async {
|
||||||
tabSessionProvider(tabId: selectedTabId).notifier,
|
final controller = ref.read(
|
||||||
);
|
tabSessionProvider(tabId: selectedTabId).notifier,
|
||||||
|
);
|
||||||
|
|
||||||
final isReaderActive = ref.read(
|
final isReaderActive = ref.read(
|
||||||
selectedTabStateProvider.select(
|
selectedTabStateProvider.select(
|
||||||
(state) => state?.readerableState.active ?? false,
|
(state) => state?.readerableState.active ?? false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
await controller.stopLoading();
|
await controller.stopLoading();
|
||||||
} else if (isReaderActive) {
|
} else if (isReaderActive) {
|
||||||
await ref
|
await ref
|
||||||
.read(readerableScreenControllerProvider.notifier)
|
.read(readerableScreenControllerProvider.notifier)
|
||||||
.toggleReaderView(false);
|
.toggleReaderView(false);
|
||||||
} else {
|
} else {
|
||||||
await controller.goBack();
|
await controller.goBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
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