This commit is contained in:
fmodf 2024-08-07 21:07:39 +02:00
parent 13b34c90de
commit 6a167f6c2c
8 changed files with 192 additions and 139 deletions

View file

@ -1,5 +1,6 @@
import CoreLocation import CoreLocation
import Foundation import Foundation
import SwiftUI
extension String { extension String {
var firstLetter: String { var firstLetter: String {
@ -57,3 +58,49 @@ extension String {
} }
} }
} }
extension String {
var firstLetterColor: Color {
let firstLetter = self.firstLetter
switch firstLetter {
case "A", "M", "Y":
return Color.Rainbow.tortoiseLight500
case "B", "N", "Z":
return Color.Rainbow.orangeLight500
case "C", "O":
return Color.Rainbow.yellowLight500
case "D", "P":
return Color.Rainbow.greenLight500
case "E", "Q":
return Color.Rainbow.blueLight500
case "F", "R":
return Color.Rainbow.magentaLight500
case "G", "S":
return Color.Rainbow.tortoiseDark500
case "H", "T":
return Color.Rainbow.orangeDark500
case "I", "U":
return Color.Rainbow.yellowDark500
case "J", "V":
return Color.Rainbow.greenDark500
case "K", "W":
return Color.Rainbow.blueDark500
case "L", "X":
return Color.Rainbow.magentaDark500
default:
return Color.Rainbow.tortoiseLight500
}
}
}

View file

@ -24,21 +24,21 @@ struct ChatsCreateMainScreen: View {
// List // List
List { List {
ChatsCreateRowButton( // ChatsCreateRowButton(
title: L10n.Chats.Create.Main.createGroup, // title: L10n.Chats.Create.Main.createGroup,
image: "person.2.fill", // image: "person.2.fill",
action: {} // action: {}
) // )
ChatsCreateRowButton( // ChatsCreateRowButton(
title: L10n.Chats.Create.Main.createPrivateGroup, // title: L10n.Chats.Create.Main.createPrivateGroup,
image: "person.2.fill", // image: "person.2.fill",
action: {} // action: {}
) // )
ChatsCreateRowButton( // ChatsCreateRowButton(
title: L10n.Chats.Create.Main.findGroup, // title: L10n.Chats.Create.Main.findGroup,
image: "magnifyingglass", // image: "magnifyingglass",
action: {} // action: {}
) // )
// for contacts list // for contacts list
let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted } let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted }
@ -54,37 +54,37 @@ struct ChatsCreateMainScreen: View {
} }
} }
private struct ChatsCreateRowButton: View { // private struct ChatsCreateRowButton: View {
var title: String // var title: String
var image: String // var image: String
var action: () -> Void // var action: () -> Void
//
var body: some View { // var body: some View {
VStack(alignment: .center, spacing: 0) { // VStack(alignment: .center, spacing: 0) {
Spacer() // Spacer()
HStack(alignment: .center, spacing: 16) { // HStack(alignment: .center, spacing: 16) {
Image(systemName: image) // Image(systemName: image)
.font(.head2) // .font(.head2)
.foregroundColor(.Material.Elements.active) // .foregroundColor(.Material.Elements.active)
.padding(.leading, 16) // .padding(.leading, 16)
Text(title) // Text(title)
.font(.body1) // .font(.body1)
.foregroundColor(.Material.Text.main) // .foregroundColor(.Material.Text.main)
Spacer() // Spacer()
} // }
Spacer() // Spacer()
Rectangle() // Rectangle()
.frame(maxWidth: .infinity) // .frame(maxWidth: .infinity)
.frame(height: 1) // .frame(height: 1)
.foregroundColor(.Material.Background.dark) // .foregroundColor(.Material.Background.dark)
} // }
.sharedListRow() // .sharedListRow()
.frame(height: 48) // .frame(height: 48)
.onTapGesture { // .onTapGesture {
action() // action()
} // }
} // }
} // }
private struct ChatsCreateRowSeparator: View { private struct ChatsCreateRowSeparator: View {
var body: some View { var body: some View {

View file

@ -53,29 +53,7 @@ private struct ChatsRow: View {
var chat: Chat var chat: Chat
var body: some View { var body: some View {
VStack(spacing: 0) { SharedListRow(iconType: .charCircle(chat.participant), text: chat.participant)
HStack(spacing: 8) {
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(.red)
Text(chat.participant.firstLetter)
.foregroundColor(.white)
.font(.body1)
}
Text(chat.participant)
.foregroundColor(Color.Material.Text.main)
.font(.body2)
Spacer()
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Material.Background.dark)
}
.sharedListRow()
.onTapGesture { .onTapGesture {
store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant))) store.dispatch(.chatsAction(.startChat(accountJid: chat.account, participantJid: chat.participant)))
} }

View file

@ -76,29 +76,33 @@ private struct ContactsScreenRow: View {
@Binding var isShowingLoader: Bool @Binding var isShowingLoader: Bool
var body: some View { var body: some View {
VStack(spacing: 0) { SharedListRow(
HStack(spacing: 8) { iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter),
ZStack { text: roster.contactBareJid
Circle() )
.frame(width: 44, height: 44) // VStack(spacing: 0) {
.foregroundColor(.red) // HStack(spacing: 8) {
Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter) // ZStack {
.foregroundColor(.white) // Circle()
.font(.body1) // .frame(width: 44, height: 44)
} // .foregroundColor(.red)
Text(roster.contactBareJid) // Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter)
.foregroundColor(Color.Material.Text.main) // .foregroundColor(.white)
.font(.body2) // .font(.body1)
Spacer() // }
} // Text(roster.contactBareJid)
.padding(.horizontal, 16) // .foregroundColor(Color.Material.Text.main)
.padding(.vertical, 4) // .font(.body2)
Rectangle() // Spacer()
.frame(maxWidth: .infinity) // }
.frame(height: 1) // .padding(.horizontal, 16)
.foregroundColor(.Material.Background.dark) // .padding(.vertical, 4)
} // Rectangle()
.sharedListRow() // .frame(maxWidth: .infinity)
// .frame(height: 1)
// .foregroundColor(.Material.Background.dark)
// }
// .sharedListRow()
.onTapGesture { .onTapGesture {
store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid))) store.dispatch(.chatsAction(.startChat(accountJid: roster.bareJid, participantJid: roster.contactBareJid)))
} }

View file

@ -77,8 +77,8 @@ private struct ContactView: View {
ZStack { ZStack {
Circle() Circle()
.frame(width: 44, height: 44) .frame(width: 44, height: 44)
.foregroundColor(.red) .foregroundColor(contactName.firstLetterColor)
Text(message.body?.getContactJid.firstLetter ?? "?") Text(contactName.firstLetter)
.foregroundColor(.white) .foregroundColor(.white)
.font(.body1) .font(.body1)
} }
@ -92,6 +92,10 @@ private struct ContactView: View {
// TODO: Jump to add roster from here // TODO: Jump to add roster from here
} }
} }
private var contactName: String {
message.body?.getContactJid ?? "?"
}
} }
private struct AttachmentView: View { private struct AttachmentView: View {

View file

@ -57,7 +57,10 @@ struct ConversationMessageRow: View {
} }
) )
} }
.sharedListRow() .listRowInsets(.zero)
.listRowSeparator(.hidden)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.Material.Background.light)
} }
private func isOutgoing() -> Bool { private func isOutgoing() -> Bool {

View file

@ -53,35 +53,10 @@ private struct ContactRow: View {
@Binding var selectedContact: Roster? @Binding var selectedContact: Roster?
var body: some View { var body: some View {
VStack(spacing: 0) { SharedListRow(
HStack(spacing: 8) { iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter),
ZStack { text: roster.contactBareJid
Circle() )
.frame(width: 44, height: 44)
.foregroundColor(.red)
Text(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter)
.foregroundColor(.white)
.font(.body1)
}
Text(roster.contactBareJid)
.foregroundColor(Color.Material.Text.main)
.font(.body2)
Spacer()
if selectedContact == roster {
Image(systemName: "checkmark")
.foregroundColor(.Material.Text.main)
.font(.body1)
.padding(.trailing, 8)
}
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Material.Background.dark)
}
.sharedListRow()
.onTapGesture { .onTapGesture {
selectedContact = roster selectedContact = roster
} }

View file

@ -1,14 +1,56 @@
import SwiftUI import SwiftUI
extension View { enum SharedListRowIconType {
func sharedListRow() -> some View { case charCircle(String)
modifier(SharedListRow()) case image(Image, Color)
}
} }
struct SharedListRow: ViewModifier { struct SharedListRow: View {
public func body(content: Content) -> some View { let iconType: SharedListRowIconType
content let text: String
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 8) {
// Icon
switch iconType {
case .charCircle(let str):
let char = str.firstLetter
let color = str.firstLetterColor
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(color)
Text(char)
.foregroundColor(.white)
.font(.body1)
}
case .image(let image, let color):
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(.clearTappable)
.overlay {
image
.foregroundColor(color)
}
}
}
// Text
Text(text)
.foregroundColor(Color.Material.Text.main)
.font(.body2)
Spacer()
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Material.Background.dark)
}
.listRowInsets(.zero) .listRowInsets(.zero)
.listRowSeparator(.hidden) .listRowSeparator(.hidden)
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)