mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
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:
parent
a556de67b0
commit
d03eb87058
31
mobile/lib/routing/gallery_guard.dart
Normal file
31
mobile/lib/routing/gallery_guard.dart
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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/backup_permission_guard.dart';
|
||||||
import 'package:immich_mobile/routing/custom_transition_builders.dart';
|
import 'package:immich_mobile/routing/custom_transition_builders.dart';
|
||||||
import 'package:immich_mobile/routing/duplicate_guard.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/routing/locked_guard.dart';
|
||||||
import 'package:immich_mobile/services/api.service.dart';
|
import 'package:immich_mobile/services/api.service.dart';
|
||||||
import 'package:immich_mobile/services/local_auth.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 DuplicateGuard _duplicateGuard;
|
||||||
late final BackupPermissionGuard _backupPermissionGuard;
|
late final BackupPermissionGuard _backupPermissionGuard;
|
||||||
late final LockedGuard _lockedGuard;
|
late final LockedGuard _lockedGuard;
|
||||||
|
late final GalleryGuard _galleryGuard;
|
||||||
|
|
||||||
AppRouter(
|
AppRouter(
|
||||||
ApiService apiService,
|
ApiService apiService,
|
||||||
@ -128,6 +130,7 @@ class AppRouter extends RootStackRouter {
|
|||||||
_lockedGuard =
|
_lockedGuard =
|
||||||
LockedGuard(apiService, secureStorageService, localAuthService);
|
LockedGuard(apiService, secureStorageService, localAuthService);
|
||||||
_backupPermissionGuard = BackupPermissionGuard(galleryPermissionNotifier);
|
_backupPermissionGuard = BackupPermissionGuard(galleryPermissionNotifier);
|
||||||
|
_galleryGuard = const GalleryGuard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -197,7 +200,7 @@ class AppRouter extends RootStackRouter {
|
|||||||
),
|
),
|
||||||
CustomRoute(
|
CustomRoute(
|
||||||
page: GalleryViewerRoute.page,
|
page: GalleryViewerRoute.page,
|
||||||
guards: [_authGuard, _duplicateGuard],
|
guards: [_authGuard, _galleryGuard],
|
||||||
transitionsBuilder: CustomTransitionsBuilders.zoomedPage,
|
transitionsBuilder: CustomTransitionsBuilders.zoomedPage,
|
||||||
),
|
),
|
||||||
AutoRoute(
|
AutoRoute(
|
||||||
|
@ -106,7 +106,6 @@ class DeepLinkService {
|
|||||||
|
|
||||||
Future<PageRouteInfo?> _buildAssetDeepLink(String assetId) async {
|
Future<PageRouteInfo?> _buildAssetDeepLink(String assetId) async {
|
||||||
final asset = await _assetService.getAssetByRemoteId(assetId);
|
final asset = await _assetService.getAssetByRemoteId(assetId);
|
||||||
|
|
||||||
if (asset == null) {
|
if (asset == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user