fix: ensure correct photo navigation in gallery details

This commit is contained in:
zhoubinjia committed 2026-05-08 15:30:49 +08:00
1 parent 082c542878
commit a5fcd48ddc
2 files changed
+8 -3

No files matched your search

@@ -216,9 +216,8 @@ fun GalleryDetailScreen(
if (photoId != null && initialJumpDone == false) {
val index = photos.indexOfFirst { it.id == photoId }
if (index != -1) {
if (index != pagerState.currentPage) {
pagerState.scrollToPage(index)
}
// 即使 index == currentPage 也执行跳转,以应对 HorizontalPager 内部键位同步导致的索引偏移
pagerState.scrollToPage(index)
initialJumpDone = true
}
}
@@ -1134,6 +1134,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
val index = currentPhotos.value.indexOfFirst { it.id == id }
if (index != -1) {
setCurrentPhoto(index)
} else {
// 如果 combine 后的列表还没更新,尝试从原始列表中查找
val photoIndex = _photos.value.indexOfFirst { it.id == id }
if (photoIndex != -1) {
setCurrentPhoto(photoIndex)
}
}
}