another.im-ios/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift

90 lines
3.1 KiB
Swift
Raw Normal View History

2024-07-02 09:56:27 +00:00
import SwiftUI
struct AttachmentContactsPickerView: View {
2024-07-09 12:37:51 +00:00
@EnvironmentObject var store: AppStore
2024-07-08 08:58:24 +00:00
@State private var selectedContact: Roster?
2024-07-02 09:56:27 +00:00
var body: some View {
2024-07-08 07:41:35 +00:00
VStack(spacing: 0) {
// Contacts list
let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted }
if !rosters.isEmpty {
List {
ForEach(rosters) { roster in
2024-07-08 08:58:24 +00:00
ContactRow(roster: roster, selectedContact: $selectedContact)
2024-07-08 07:41:35 +00:00
}
}
.listStyle(.plain)
.background(Color.Material.Background.light)
} else {
Spacer()
}
2024-07-08 08:58:24 +00:00
// Send panel
Rectangle()
.foregroundColor(.Material.Shape.black)
.frame(maxWidth: .infinity)
.frame(height: selectedContact == nil ? 0 : 50)
.overlay {
HStack {
Text(L10n.Attachment.Send.contact)
.foregroundColor(.Material.Text.white)
.font(.body1)
Image(systemName: "arrow.up.circle")
.foregroundColor(.Material.Text.white)
.font(.body1)
.padding(.leading, 8)
}
.padding()
}
.clipped()
.onTapGesture {
2024-07-10 11:09:59 +00:00
if let selectedContact = selectedContact {
2024-07-10 14:48:18 +00:00
store.dispatch(.sharingAction(.shareContact(jid: selectedContact.contactBareJid)))
2024-07-10 14:13:47 +00:00
store.dispatch(.sharingAction(.showSharing(false)))
2024-07-10 11:09:59 +00:00
}
2024-07-08 08:58:24 +00:00
}
2024-07-08 07:41:35 +00:00
}
}
}
private struct ContactRow: View {
var roster: Roster
2024-07-08 08:58:24 +00:00
@Binding var selectedContact: Roster?
2024-07-08 07:41:35 +00:00
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 8) {
ZStack {
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()
2024-07-08 08:58:24 +00:00
if selectedContact == roster {
Image(systemName: "checkmark")
.foregroundColor(.Material.Text.main)
.font(.body1)
.padding(.trailing, 8)
}
2024-07-08 07:41:35 +00:00
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Material.Background.dark)
}
.sharedListRow()
.onTapGesture {
2024-07-08 08:58:24 +00:00
selectedContact = roster
2024-07-08 07:41:35 +00:00
}
2024-07-02 09:56:27 +00:00
}
}