Fix initial filter (#229)

This commit is contained in:
Ashinch 2022-10-08 21:19:43 +08:00 committed by GitHub
parent 352fe36980
commit d948e15fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View File

@ -129,7 +129,12 @@ fun FlowPage(
},
) {
scope.launch {
flowUiState.listState.scrollToItem(0)
// java.lang.NullPointerException: Attempt to invoke virtual method
// 'boolean androidx.compose.ui.node.LayoutNode.getNeedsOnPositionedDispatch$ui_release()'
// on a null object reference
if (flowUiState.listState.firstVisibleItemIndex != 0) {
flowUiState.listState.scrollToItem(0)
}
markAsRead = !markAsRead
onSearch = false
}
@ -145,7 +150,12 @@ fun FlowPage(
},
) {
scope.launch {
flowUiState.listState.scrollToItem(0)
// java.lang.NullPointerException: Attempt to invoke virtual method
// 'boolean androidx.compose.ui.node.LayoutNode.getNeedsOnPositionedDispatch$ui_release()'
// on a null object reference
if (flowUiState.listState.firstVisibleItemIndex != 0) {
flowUiState.listState.scrollToItem(0)
}
onSearch = !onSearch
}
}
@ -249,7 +259,14 @@ fun FlowPage(
filterBarPadding = filterBarPadding.dp,
filterBarTonalElevation = filterBarTonalElevation.value.dp,
) {
flowViewModel.scrollToItem(0)
scope.launch {
// java.lang.NullPointerException: Attempt to invoke virtual method
// 'boolean androidx.compose.ui.node.LayoutNode.getNeedsOnPositionedDispatch$ui_release()'
// on a null object reference
if (flowUiState.listState.firstVisibleItemIndex != 0) {
flowUiState.listState.scrollToItem(0)
}
}
homeViewModel.changeFilter(filterUiState.copy(filter = it))
homeViewModel.fetchArticles()
}

View File

@ -30,12 +30,6 @@ class FlowViewModel @Inject constructor(
}
}
fun scrollToItem(index: Int) {
viewModelScope.launch {
_flowUiState.value.listState.scrollToItem(index)
}
}
fun markAsRead(
groupId: String?,
feedId: String?,