mobile: always show chat list search (#2517)

This commit is contained in:
spaced4ndy
2023-05-26 15:49:26 +04:00
committed by GitHub
parent 3af2848275
commit 42d4f94fec
2 changed files with 24 additions and 18 deletions

View File

@@ -176,7 +176,7 @@ private fun ChatListToolbar(chatModel: ChatModel, drawerState: DrawerState, user
BackHandler(onBack = hideSearchOnBack)
}
val barButtons = arrayListOf<@Composable RowScope.() -> Unit>()
if (chatModel.chats.size >= 8) {
if (chatModel.chats.size > 0) {
barButtons.add {
IconButton({ showSearch = true }) {
Icon(painterResource(R.drawable.ic_search_500), stringResource(android.R.string.search_go).capitalize(Locale.current), tint = MaterialTheme.colors.primary)

View File

@@ -29,11 +29,7 @@ struct ChatListView: View {
if chatModel.chats.isEmpty {
onboardingButtons()
}
if chatModel.chats.count > 8 {
chatList.searchable(text: $searchText)
} else {
chatList
}
chatListView
}
}
if userPickerVisible {
@@ -47,18 +43,12 @@ struct ChatListView: View {
}
}
var chatList: some View {
List {
ForEach(filteredChats(), id: \.viewId) { chat in
ChatListNavLink(chat: chat)
.padding(.trailing, -16)
.disabled(chatModel.chatRunning != true)
}
}
.onChange(of: chatModel.chatId) { _ in
if chatModel.chatId == nil, let chatId = chatModel.chatToTop {
chatModel.chatToTop = nil
chatModel.popChat(chatId)
private var chatListView: some View {
VStack {
if chatModel.chats.count > 0 {
chatList.searchable(text: $searchText)
} else {
chatList
}
}
.onChange(of: chatModel.appOpenUrl) { _ in connectViaUrl() }
@@ -116,6 +106,22 @@ struct ChatListView: View {
}
}
private var chatList: some View {
List {
ForEach(filteredChats(), id: \.viewId) { chat in
ChatListNavLink(chat: chat)
.padding(.trailing, -16)
.disabled(chatModel.chatRunning != true)
}
}
.onChange(of: chatModel.chatId) { _ in
if chatModel.chatId == nil, let chatId = chatModel.chatToTop {
chatModel.chatToTop = nil
chatModel.popChat(chatId)
}
}
}
private func unreadBadge(_ text: Text? = Text(" "), size: CGFloat = 18) -> some View {
Circle()
.frame(width: size, height: size)