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

* initial attempt at new guard

* do not resolve the route when replaced

* Update gallery_guard.dart comment

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
Brandon Wees 2025-07-08 10:50:59 -05:00 committed by GitHub
parent a556de67b0
commit d03eb87058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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(

View File

@ -106,7 +106,6 @@ class DeepLinkService {
Future<PageRouteInfo?> _buildAssetDeepLink(String assetId) async {
final asset = await _assetService.getAssetByRemoteId(assetId);
if (asset == null) {
return null;
}