Skip to content

Commit 9134611

Browse files
committed
improve back/forward navigation
1 parent 81611ab commit 9134611

File tree

1 file changed

+45
-55
lines changed
  • app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules

1 file changed

+45
-55
lines changed

app/lib/features/geckoview/features/browser/presentation/widgets/browser_modules/bottom_app_bar.dart

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import 'package:weblibre/presentation/hooks/menu_controller.dart';
5656
import 'package:weblibre/presentation/icons/tor_icons.dart';
5757
import 'package:weblibre/presentation/widgets/selectable_chips.dart';
5858
import 'package:weblibre/presentation/widgets/url_icon.dart';
59-
import 'package:weblibre/utils/ui_helper.dart' as ui_helper;
6059

6160
class BrowserTopAppBar extends HookConsumerWidget {
6261
final bool showMainToolbar;
@@ -400,7 +399,8 @@ class ContextualToolbar extends HookConsumerWidget {
400399
return Row(
401400
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
402401
children: [
403-
if (tabState?.historyState.canGoBack == true)
402+
if (tabState?.historyState.canGoBack == true ||
403+
tabState?.isLoading == true)
404404
NavigateBackButton(
405405
selectedTabId: selectedTabId,
406406
isLoading: tabState?.isLoading ?? false,
@@ -829,37 +829,19 @@ class NavigationMenuButton extends HookConsumerWidget {
829829
return Row(
830830
children: [
831831
Expanded(
832-
child: (history?.canGoBack == true || isLoading)
833-
? NavigateBackButton(
834-
selectedTabId: selectedTabId,
835-
isLoading: isLoading,
836-
menuControllerToClose: hamburgerMenuController,
837-
)
838-
: IconButton(
839-
onPressed: () async {
840-
await ref
841-
.read(tabRepositoryProvider.notifier)
842-
.closeTab(selectedTabId!);
843-
844-
hamburgerMenuController.close();
845-
846-
if (context.mounted) {
847-
ui_helper.showTabUndoClose(
848-
context,
849-
ref
850-
.read(tabRepositoryProvider.notifier)
851-
.undoClose,
852-
);
853-
}
854-
},
855-
icon: const Icon(Icons.close),
856-
),
832+
child: NavigateBackButton(
833+
selectedTabId: selectedTabId,
834+
isLoading: isLoading,
835+
menuControllerToClose: hamburgerMenuController,
836+
canGoBack: history?.canGoBack == true,
837+
),
857838
),
858839
const SizedBox(height: 48, child: VerticalDivider()),
859840
Expanded(
860841
child: NavigateForwardButton(
861842
selectedTabId: selectedTabId,
862843
menuControllerToClose: hamburgerMenuController,
844+
canGoForward: history?.canGoForward == true,
863845
),
864846
),
865847
],
@@ -876,22 +858,26 @@ class NavigateForwardButton extends HookConsumerWidget {
876858
super.key,
877859
required this.selectedTabId,
878860
this.menuControllerToClose,
861+
this.canGoForward = true,
879862
});
880863

881864
final String? selectedTabId;
882865
final MenuController? menuControllerToClose;
866+
final bool canGoForward;
883867

884868
@override
885869
Widget build(BuildContext context, WidgetRef ref) {
886870
return IconButton(
887-
onPressed: () async {
888-
final controller = ref.read(
889-
tabSessionProvider(tabId: selectedTabId).notifier,
890-
);
871+
onPressed: canGoForward
872+
? () async {
873+
final controller = ref.read(
874+
tabSessionProvider(tabId: selectedTabId).notifier,
875+
);
891876

892-
await controller.goForward();
893-
menuControllerToClose?.close();
894-
},
877+
await controller.goForward();
878+
menuControllerToClose?.close();
879+
}
880+
: null,
895881
icon: const Icon(Icons.arrow_forward),
896882
);
897883
}
@@ -903,39 +889,43 @@ class NavigateBackButton extends HookConsumerWidget {
903889
required this.selectedTabId,
904890
required this.isLoading,
905891
this.menuControllerToClose,
892+
this.canGoBack = true,
906893
});
907894

908895
final String? selectedTabId;
909896
final bool isLoading;
910897
final MenuController? menuControllerToClose;
898+
final bool canGoBack;
911899

912900
@override
913901
Widget build(BuildContext context, WidgetRef ref) {
914902
return IconButton(
915-
onPressed: () async {
916-
final controller = ref.read(
917-
tabSessionProvider(tabId: selectedTabId).notifier,
918-
);
903+
onPressed: (canGoBack || isLoading)
904+
? () async {
905+
final controller = ref.read(
906+
tabSessionProvider(tabId: selectedTabId).notifier,
907+
);
919908

920-
final isReaderActive = ref.read(
921-
selectedTabStateProvider.select(
922-
(state) => state?.readerableState.active ?? false,
923-
),
924-
);
909+
final isReaderActive = ref.read(
910+
selectedTabStateProvider.select(
911+
(state) => state?.readerableState.active ?? false,
912+
),
913+
);
925914

926-
if (isLoading) {
927-
await controller.stopLoading();
928-
} else if (isReaderActive) {
929-
await ref
930-
.read(readerableScreenControllerProvider.notifier)
931-
.toggleReaderView(false);
932-
} else {
933-
await controller.goBack();
934-
}
915+
if (isLoading) {
916+
await controller.stopLoading();
917+
} else if (isReaderActive) {
918+
await ref
919+
.read(readerableScreenControllerProvider.notifier)
920+
.toggleReaderView(false);
921+
} else {
922+
await controller.goBack();
923+
}
935924

936-
menuControllerToClose?.close();
937-
},
938-
icon: const Icon(Icons.arrow_back),
925+
menuControllerToClose?.close();
926+
}
927+
: null,
928+
icon: isLoading ? const Icon(Icons.close) : const Icon(Icons.arrow_back),
939929
);
940930
}
941931
}

0 commit comments

Comments
 (0)