mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 18:35:49 +00:00
search chats, longer emojis (#295)
* search chats, longer emojis * simplify
This commit is contained in:
committed by
GitHub
parent
aa2bc545db
commit
61afb64dd7
@@ -13,10 +13,11 @@ struct EmojiItemView: View {
|
||||
|
||||
var body: some View {
|
||||
let sent = chatItem.chatDir.sent
|
||||
let s = chatItem.content.text.trimmingCharacters(in: .whitespaces)
|
||||
|
||||
VStack(spacing: 1) {
|
||||
Text(chatItem.content.text.trimmingCharacters(in: .whitespaces))
|
||||
.font(emojiFont)
|
||||
Text(s)
|
||||
.font(s.count < 4 ? largeEmojiFont : mediumEmojiFont)
|
||||
.padding(.top, 8)
|
||||
.padding(.horizontal, 6)
|
||||
.frame(maxWidth: .infinity, alignment: sent ? .trailing : .leading)
|
||||
|
||||
@@ -105,7 +105,7 @@ struct ChatView: View {
|
||||
}
|
||||
|
||||
func markAllRead() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
if chatModel.chatId == chat.id {
|
||||
markChatRead(chat)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ func isEmoji(_ c: Character) -> Bool {
|
||||
|
||||
func isShortEmoji(_ str: String) -> Bool {
|
||||
let s = str.trimmingCharacters(in: .whitespaces)
|
||||
return s.count > 0 && s.count <= 4 && s.allSatisfy(isEmoji)
|
||||
return s.count > 0 && s.count <= 5 && s.allSatisfy(isEmoji)
|
||||
}
|
||||
|
||||
let emojiFont = Font.custom("Emoji", size: 48, relativeTo: .largeTitle)
|
||||
let largeEmojiFont = Font.custom("Emoji", size: 48, relativeTo: .largeTitle)
|
||||
let mediumEmojiFont = Font.custom("Emoji", size: 36, relativeTo: .largeTitle)
|
||||
|
||||
@@ -73,7 +73,11 @@ struct SendMessageView: View {
|
||||
func updateHeight(_ g: GeometryProxy) -> Color {
|
||||
DispatchQueue.main.async {
|
||||
teHeight = min(max(g.frame(in: .local).size.height, minHeight), maxHeight)
|
||||
teFont = isShortEmoji(message) ? emojiFont : .body
|
||||
teFont = isShortEmoji(message)
|
||||
? message.count < 4
|
||||
? largeEmojiFont
|
||||
: mediumEmojiFont
|
||||
: .body
|
||||
}
|
||||
return Color.clear
|
||||
}
|
||||
|
||||
@@ -12,11 +12,12 @@ struct ChatListView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
// not really used in this view
|
||||
@State private var showSettings = false
|
||||
@State private var searchText = ""
|
||||
|
||||
var user: User
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
let v = NavigationView {
|
||||
List {
|
||||
if chatModel.chats.isEmpty {
|
||||
VStack(alignment: .leading) {
|
||||
@@ -28,7 +29,7 @@ struct ChatListView: View {
|
||||
.padding(.leading)
|
||||
}
|
||||
}
|
||||
ForEach(chatModel.chats) { chat in
|
||||
ForEach(filteredChats()) { chat in
|
||||
ChatListNavLink(chat: chat)
|
||||
.padding(.trailing, -16)
|
||||
}
|
||||
@@ -48,6 +49,7 @@ struct ChatListView: View {
|
||||
.offset(x: -8)
|
||||
.listStyle(.plain)
|
||||
.navigationTitle(chatModel.chats.isEmpty ? "Welcome \(user.displayName)!" : "Your chats")
|
||||
.navigationBarTitleDisplayMode(chatModel.chats.count > 8 ? .inline : .large)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
SettingsButton()
|
||||
@@ -58,6 +60,20 @@ struct ChatListView: View {
|
||||
}
|
||||
}
|
||||
.navigationViewStyle(.stack)
|
||||
|
||||
if chatModel.chats.count > 8 {
|
||||
v.searchable(text: $searchText)
|
||||
} else {
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
private func filteredChats() -> [Chat] {
|
||||
let s = searchText.trimmingCharacters(in: .whitespaces).localizedLowercase
|
||||
return s == ""
|
||||
? chatModel.chats
|
||||
: chatModel.chats.filter { $0.chatInfo.chatViewName.localizedLowercase.contains(s) }
|
||||
}
|
||||
}
|
||||
|
||||
private func connectViaUrlAlert(_ url: URL) -> Alert {
|
||||
|
||||
Reference in New Issue
Block a user