Skip to content

High performance self-hosted photo and video management solution.

fix(mobile): deeplinking to asset view while viewer is already open (#19812)

Brandon Weesd03eb8705879
diff --git a/mobile/lib/routing/gallery_guard.dart b/mobile/lib/routing/gallery_guard.dart
new file mode 100644
index 0000000000..fcac142271
--- /dev/null
+++ b/mobile/lib/routing/gallery_guard.dart
@@ -0,0 +1,31 @@
+import 'package:auto_route/auto_route.dart';
+import 'package:immich_mobile/routing/router.dart';
+
+/// Handles duplicate navigation to this route (primarily for deep linking)
+class GalleryGuard extends AutoRouteGuard {
+ const GalleryGuard();
+ @override
+ void onNavigation(NavigationResolver resolver, StackRouter router) async {
+ final newRouteName = resolver.route.name;
+ final currentTopRouteName =
+ router.stack.isNotEmpty ? router.stack.last.name : null;
+
+ if (currentTopRouteName == newRouteName) {
+ // Replace instead of pushing duplicate
+ final args = resolver.route.args as GalleryViewerRouteArgs;
+
+ router.replace(
+ GalleryViewerRoute(
+ renderList: args.renderList,
+ initialIndex: args.initialIndex,
+ heroOffset: args.heroOffset,
+ showStack: args.showStack,
+ ),
+ );
+ // Prevent further navigation since we replaced the route
+ resolver.next(false);
+ return;
+ }
+ resolver.next(true);
+ }
+}
diff --git a/mobile/lib/routing/router.dart b/mobile/lib/routing/router.dart
index 2dbd835ce8..18aa937a9d 100644
--- a/mobile/lib/routing/router.dart
+++ b/mobile/lib/routing/router.dart
@@ -91,6 +91,7 @@ import 'package:immich_mobile/routing/auth_guard.dart';
import 'package:immich_mobile/routing/backup_permission_guard.dart';
import 'package:immich_mobile/routing/custom_transition_builders.dart';
import 'package:immich_mobile/routing/duplicate_guard.dart';
+import 'package:immich_mobile/routing/gallery_guard.dart';
import 'package:immich_mobile/routing/locked_guard.dart';
import 'package:immich_mobile/services/api.service.dart';
import 'package:immich_mobile/services/local_auth.service.dart';
@@ -116,6 +117,7 @@ class AppRouter extends RootStackRouter {
late final DuplicateGuard _duplicateGuard;
late final BackupPermissionGuard _backupPermissionGuard;
late final LockedGuard _lockedGuard;
+ late final GalleryGuard _galleryGuard;
AppRouter(
ApiService apiService,
@@ -128,6 +130,7 @@ class AppRouter extends RootStackRouter {
_lockedGuard =
LockedGuard(apiService, secureStorageService, localAuthService);
_backupPermissionGuard = BackupPermissionGuard(galleryPermissionNotifier);
+ _galleryGuard = const GalleryGuard();
}
@override
@@ -197,7 +200,7 @@ class AppRouter extends RootStackRouter {
),
CustomRoute(
page: GalleryViewerRoute.page,
- guards: [_authGuard, _duplicateGuard],
+ guards: [_authGuard, _galleryGuard],
transitionsBuilder: CustomTransitionsBuilders.zoomedPage,
),
AutoRoute(
diff --git a/mobile/lib/services/deep_link.service.dart b/mobile/lib/services/deep_link.service.dart
index 2665d9ee52..e97a370967 100644
--- a/mobile/lib/services/deep_link.service.dart
+++ b/mobile/lib/services/deep_link.service.dart
@@ -106,7 +106,6 @@ class DeepLinkService {
Future<PageRouteInfo?> _buildAssetDeepLink(String assetId) async {
final asset = await _assetService.getAssetByRemoteId(assetId);
-
if (asset == null) {
return null;
}