mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 02:57:04 +05:30
feat(android): add search UI
This commit is contained in:
parent
5e91e20c51
commit
8d6aba9865
1 changed files with 87 additions and 0 deletions
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.android.ui.lists
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.SearchOff
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.semantics.isTraversalGroup
|
||||||
|
import androidx.compose.ui.semantics.semantics
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.zIndex
|
||||||
|
import androidx.paging.compose.LazyPagingItems
|
||||||
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
|
import dev.msfjarvis.claw.common.ui.SearchBar
|
||||||
|
import dev.msfjarvis.claw.database.local.SavedPost
|
||||||
|
import dev.msfjarvis.claw.model.LobstersPost
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SearchList(
|
||||||
|
items: LazyPagingItems<LobstersPost>,
|
||||||
|
listState: LazyListState,
|
||||||
|
isPostSaved: suspend (SavedPost) -> Boolean,
|
||||||
|
postActions: PostActions,
|
||||||
|
searchQuery: String,
|
||||||
|
setSearchQuery: (String) -> Unit,
|
||||||
|
triggerSearch: (String) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
DisposableEffect(true) {
|
||||||
|
// Clear search field when navigating away
|
||||||
|
onDispose { triggerSearch("") }
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchActive by remember { mutableStateOf(false) }
|
||||||
|
Column(modifier = Modifier.semantics { isTraversalGroup = true }.zIndex(1f).fillMaxWidth()) {
|
||||||
|
SearchBar(
|
||||||
|
value = searchQuery,
|
||||||
|
onValueChange = setSearchQuery,
|
||||||
|
onSearch = {
|
||||||
|
triggerSearch(it)
|
||||||
|
searchActive = true
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),
|
||||||
|
)
|
||||||
|
if (searchActive) {
|
||||||
|
NetworkPosts(
|
||||||
|
lazyPagingItems = items,
|
||||||
|
listState = listState,
|
||||||
|
isPostSaved = isPostSaved,
|
||||||
|
postActions = postActions,
|
||||||
|
modifier = modifier,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
|
Column(modifier = Modifier.align(Alignment.Center)) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.SearchOff,
|
||||||
|
contentDescription = "Empty inbox icon",
|
||||||
|
modifier = Modifier.align(Alignment.CenterHorizontally).size(36.dp),
|
||||||
|
)
|
||||||
|
Text(text = "Nothing to see here", style = MaterialTheme.typography.headlineSmall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue