fix(mutual): map Match prefill scrolls to time-range card via scrollToItem

Compose ui 1.11.x (BOM 2026.06.01) ignores the LazyListState
firstVisibleItemIndex constructor parameter - the list always starts at
item 0. Restore the scrollToItem approach (verified effective by
Robolectric Compose UI tests) and keep the auto-started query.
This commit is contained in:
atsunatsu committed 2026-09-22 12:23:50 +08:00
1 parent 14bd984327
commit 466f2f6088
2 files changed
+28 -6

No files matched your search

@@ -369,6 +369,20 @@ private fun MutualContent(
)
}
}
// Prefill from the map's grid-QSO dialog "Match" button: once the page is
// laid out, jump straight to the time-range card. Index accounts for the
// optional error card at the top (error = 0, station inputs = 1, time
// range = 2; else 1). scrollToItem is used instead of initializing the
// LazyListState at index 1: the constructor parameter is ignored by this
// Compose version (verified in tests), while scrollToItem lands correctly.
val matchSearchIndex = if (state.errorMessage != null) 2 else 1
LaunchedEffect(state.scrollToTimeRange, matchSearchIndex) {
if (state.scrollToTimeRange) {
listState.scrollToItem(matchSearchIndex)
viewModel.consumeScrollToTimeRange()
}
}
}
@Composable
@@ -55,7 +55,11 @@ data class MutualUiState(
val hasSearched: Boolean = false,
val selectedPassIndex: Int = -1,
val isUtc: Boolean = false,
val errorMessage: String? = null
val errorMessage: String? = null,
// One-shot flag set by prefillMatchFromGrid() (map grid → Match button):
// the page scrolls to the time-range card after the first layout, then
// consumeScrollToTimeRange() clears it.
val scrollToTimeRange: Boolean = false
)
class MutualViewModel(
@@ -187,9 +191,8 @@ class MutualViewModel(
* Pre-fill the match page for a target grid picked from the map's grid-QSO
* dialog ("Match" button): set the opposite-station grid (with its
* coordinates), reset the time range to 24h, start the query immediately
* so results are ready when the page opens, and position the list at the
* time-range card (LazyColumn item 1, the card right below the station
* inputs) so the page opens showing it at the top.
* so results are ready when the page opens, and flag the page to scroll
* straight to the time-range card once it is laid out.
*/
fun prefillMatchFromGrid(grid: String) {
val g = grid.trim().uppercase()
@@ -199,10 +202,15 @@ class MutualViewModel(
stationBGrid = g,
stationBLat = pos?.let { p -> "%.4f".format(p.latitude) } ?: it.stationBLat,
stationBLon = pos?.let { p -> "%.4f".format(p.longitude) } ?: it.stationBLon,
hoursAhead = 24
hoursAhead = 24,
scrollToTimeRange = true
)
}
queryMutualPasses(initialScrollIndex = 1)
queryMutualPasses()
}
fun consumeScrollToTimeRange() {
_uiState.update { it.copy(scrollToTimeRange = false) }
}
fun queryMutualPasses(initialScrollIndex: Int = 0) {