mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-05 12:07:25 +00:00
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:
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
|
@Composable
|
||||||
|
|||||||
+14
-6
@@ -55,7 +55,11 @@ data class MutualUiState(
|
|||||||
val hasSearched: Boolean = false,
|
val hasSearched: Boolean = false,
|
||||||
val selectedPassIndex: Int = -1,
|
val selectedPassIndex: Int = -1,
|
||||||
val isUtc: Boolean = false,
|
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(
|
class MutualViewModel(
|
||||||
@@ -187,9 +191,8 @@ class MutualViewModel(
|
|||||||
* Pre-fill the match page for a target grid picked from the map's grid-QSO
|
* 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
|
* dialog ("Match" button): set the opposite-station grid (with its
|
||||||
* coordinates), reset the time range to 24h, start the query immediately
|
* 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
|
* so results are ready when the page opens, and flag the page to scroll
|
||||||
* time-range card (LazyColumn item 1, the card right below the station
|
* straight to the time-range card once it is laid out.
|
||||||
* inputs) so the page opens showing it at the top.
|
|
||||||
*/
|
*/
|
||||||
fun prefillMatchFromGrid(grid: String) {
|
fun prefillMatchFromGrid(grid: String) {
|
||||||
val g = grid.trim().uppercase()
|
val g = grid.trim().uppercase()
|
||||||
@@ -199,10 +202,15 @@ class MutualViewModel(
|
|||||||
stationBGrid = g,
|
stationBGrid = g,
|
||||||
stationBLat = pos?.let { p -> "%.4f".format(p.latitude) } ?: it.stationBLat,
|
stationBLat = pos?.let { p -> "%.4f".format(p.latitude) } ?: it.stationBLat,
|
||||||
stationBLon = pos?.let { p -> "%.4f".format(p.longitude) } ?: it.stationBLon,
|
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) {
|
fun queryMutualPasses(initialScrollIndex: Int = 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user