fix(android): Alben-Tab behaelt die Scrollposition beim Zurueck

LaunchedEffect(state.albumSort) { scrollToItem(0) } feuerte nicht nur beim
Sortierwechsel, sondern auch beim ersten Compose nach der Rueckkehr aus einem
Album — die im ViewModel gehaltene Position wurde also sofort ueberschrieben.
Das Hochscrollen sitzt jetzt in setAlbumSort() und laeuft nur bei echtem
Wechsel; dazu zwei ungenutzte remember*State-Importe entfernt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
marcandClaude Opus 5 committed 2026-09-02 21:21:38 +02:00
1 parent 3e8897b551
commit 0029b89de4
3 files changed
+18 -3

No files matched your search

+10
View File
@@ -64,6 +64,16 @@ Versioning: two-part `MAJOR.MINOR` — each release bumps the minor (features an
---
## [Unreleased]
### Fixed
- **Alben-Tab sprang beim Zurück wieder nach oben** — ein `LaunchedEffect(albumSort)` scrollte auf
Position 0. Der feuert aber nicht nur beim Sortierwechsel, sondern auch bei jedem Neu-Composen,
also genau beim Zurückkommen aus einem Album: die gemerkte Position wurde sofort verworfen. Das
Hochscrollen sitzt jetzt in `LibraryViewModel.setAlbumSort()` und läuft nur bei echtem Wechsel.
---
## [2.2] — 2026-08-22
A cleanup-and-parity release: the **Song Importer moves into the Global Search field** (one field,
@@ -7,9 +7,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
@@ -167,7 +165,9 @@ fun LibraryScreen(
}
}
val albumGridState = vm.albumsGridState // hoisted → survives album drill-in/back
LaunchedEffect(state.albumSort) { albumGridState.scrollToItem(0) }
// Kein LaunchedEffect(state.albumSort) zum Hochscrollen: der liefe auch beim ersten
// Compose nach dem Zurückkommen und würde die gemerkte Position sofort verwerfen.
// Das Hochscrollen passiert jetzt in vm.setAlbumSort(), also nur bei echtem Wechsel.
LazyVerticalGrid(
state = albumGridState,
columns = GridCells.Adaptive(minSize = 150.dp),
@@ -45,7 +45,12 @@ class LibraryViewModel(app: Application) : AndroidViewModel(app) {
init { loadPlaylists() }
fun setAlbumSort(sort: AlbumSort) {
if (sort == _state.value.albumSort) return
_state.value = _state.value.copy(albumSort = sort)
// Eine andere Sortierung heißt eine andere Liste — dort oben anfangen. Bewusst hier und
// nicht als LaunchedEffect im Screen: der feuert auch bei jedem Neu-Composen (z. B. nach
// dem Zurück aus einem Album) und hätte die gemerkte Scrollposition jedes Mal verworfen.
viewModelScope.launch { albumsGridState.scrollToItem(0) }
}
fun selectTab(tab: LibraryTab) {