Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): preserve search state in flow page #906

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading