Commit 704697b
committed
fix(mediaviewer): Fix wrong image shown after opening from a group
Opening the first image of a group (or any image within the first two
positions of the currently loaded media) triggered an older-history
prefetch that prepends older items to the pager's item list and
shifts the pager to compensate. That shift correction was emitted as
a one-shot SharedFlow event, collected in a long-lived LaunchedEffect
whose closure captured the item count from the composition active
when the effect first launched. By the time the event fired, the item
list had already grown, but the effect's clamp (`items.size` / later
`pagerState.pageCount`) still reflected the stale, smaller count, so
the pager settled on the wrong, small index - showing an unrelated,
often much older image a moment after the tap.
Moved the shift into UiState itself (MediaViewerViewModel.PendingShift)
so the Compose side always applies it from the very same state
snapshot as the already-updated item list, removing the possibility
of a stale item count at the point the correction is applied.
Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>1 parent ca2e285 commit 704697b
2 files changed
Lines changed: 17 additions & 19 deletions
File tree
- app/src/main/java/com/nextcloud/talk/mediaviewer
- activities
- viewmodels
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
129 | 128 | | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
Lines changed: 11 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | 34 | | |
36 | 35 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 76 | + | |
82 | 77 | | |
83 | 78 | | |
84 | 79 | | |
| |||
112 | 107 | | |
113 | 108 | | |
114 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
| |||
215 | 214 | | |
216 | 215 | | |
217 | 216 | | |
218 | | - | |
219 | 217 | | |
220 | 218 | | |
221 | 219 | | |
222 | 220 | | |
223 | 221 | | |
224 | 222 | | |
225 | | - | |
| 223 | + | |
| 224 | + | |
226 | 225 | | |
227 | 226 | | |
228 | | - | |
229 | 227 | | |
230 | 228 | | |
231 | 229 | | |
| |||
0 commit comments