mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix home header not updating & row movement (#627)
## Description Removes an incorrect optimization for showing the home page header Separates logic for focusing on rows on the home page ### Related issues Fixes #624 Fixes #620
This commit is contained in:
parent
36d26a5ead
commit
9345d0a698
2 changed files with 19 additions and 12 deletions
|
|
@ -78,12 +78,13 @@ inline fun <T> List<T>.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? {
|
||||||
/**
|
/**
|
||||||
* Try to call [FocusRequester.requestFocus], but catch & log the exception if something is not configured properly
|
* Try to call [FocusRequester.requestFocus], but catch & log the exception if something is not configured properly
|
||||||
*/
|
*/
|
||||||
fun FocusRequester.tryRequestFocus(): Boolean =
|
fun FocusRequester.tryRequestFocus(tag: String? = null): Boolean =
|
||||||
try {
|
try {
|
||||||
requestFocus()
|
requestFocus()
|
||||||
|
tag?.let { Timber.v("Request focus tag=%s", tag) }
|
||||||
true
|
true
|
||||||
} catch (ex: IllegalStateException) {
|
} catch (ex: IllegalStateException) {
|
||||||
Timber.w(ex, "Failed to request focus")
|
Timber.w(ex, "Failed to request focus, tag=%s", tag)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,28 +226,34 @@ fun HomePageContent(
|
||||||
mutableStateOf(RowColumn(firstRow, 0))
|
mutableStateOf(RowColumn(firstRow, 0))
|
||||||
}
|
}
|
||||||
val focusedItem =
|
val focusedItem =
|
||||||
remember(position) {
|
position.let {
|
||||||
position.let {
|
(homeRows.getOrNull(it.row) as? HomeRowLoadingState.Success)?.items?.getOrNull(it.column)
|
||||||
(homeRows.getOrNull(it.row) as? HomeRowLoadingState.Success)?.items?.getOrNull(it.column)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val rowFocusRequesters = remember(homeRows.size) { List(homeRows.size) { FocusRequester() } }
|
val rowFocusRequesters = remember(homeRows.size) { List(homeRows.size) { FocusRequester() } }
|
||||||
var focused by rememberSaveable { mutableStateOf(false) }
|
var firstFocused by rememberSaveable { mutableStateOf(false) }
|
||||||
LaunchedEffect(homeRows) {
|
LaunchedEffect(homeRows) {
|
||||||
if (!focused) {
|
if (!firstFocused) {
|
||||||
|
// Waiting for the first home row to load, then focus on it
|
||||||
homeRows
|
homeRows
|
||||||
.indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() }
|
.indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() }
|
||||||
.takeIf { it >= 0 }
|
.takeIf { it >= 0 }
|
||||||
?.let {
|
?.let {
|
||||||
rowFocusRequesters[it].tryRequestFocus()
|
rowFocusRequesters[it].tryRequestFocus()
|
||||||
delay(50)
|
delay(50)
|
||||||
listState.animateScrollToItem(position.row)
|
listState.scrollToItem(it)
|
||||||
focused = true
|
firstFocused = true
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
rowFocusRequesters.getOrNull(position.row)?.tryRequestFocus()
|
}
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
if (firstFocused) {
|
||||||
|
// After the first home row was loaded & focused, page recompositions should focus on the positioned row
|
||||||
|
val index = position.row
|
||||||
|
rowFocusRequesters.getOrNull(index)?.tryRequestFocus()
|
||||||
|
delay(50)
|
||||||
|
listState.scrollToItem(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LaunchedEffect(position) {
|
LaunchedEffect(position) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue