Skip to content

Commit

Permalink
feat(ui): preserve search state in flow page
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Nov 23, 2024
1 parent 9766788 commit e2f27d1
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -151,7 +152,7 @@ fun FlowPage(
val scope = rememberCoroutineScope()
val focusRequester = remember { FocusRequester() }
var markAsRead by remember { mutableStateOf(false) }
var onSearch by remember { mutableStateOf(false) }
var onSearch by rememberSaveable { mutableStateOf(false) }

val owner = LocalLifecycleOwner.current

Expand Down Expand Up @@ -237,15 +238,10 @@ fun FlowPage(
}

LaunchedEffect(onSearch) {
snapshotFlow { onSearch }.collect {
if (it) {
delay(100) // ???
focusRequester.requestFocus()
} else {
keyboardController?.hide()
if (homeUiState.searchContent.isNotBlank()) {
homeViewModel.inputSearchContent("")
}
if (!onSearch) {
keyboardController?.hide()
if (homeUiState.searchContent.isNotBlank()) {
homeViewModel.inputSearchContent("")
}
}
}
Expand Down Expand Up @@ -341,6 +337,10 @@ fun FlowPage(
flowUiState.listState.animateScrollToItem(0)
}
onSearch = !onSearch
if (onSearch) {
delay(100)
focusRequester.requestFocus()
}
}
}
}, colors = TopAppBarDefaults.topAppBarColors(
Expand Down Expand Up @@ -424,7 +424,6 @@ fun FlowPage(
articleListTonalElevation = articleListTonalElevation.value,
isSwipeEnabled = { listState.isScrollInProgress },
onClick = {
onSearch = false
navController.navigate("${RouteName.READING}/${it.article.id}") {
launchSingleTop = true
}
Expand Down

0 comments on commit e2f27d1

Please sign in to comment.