fmodf
b3b3b3aef7
Reviewed-on: narayana/conversations-classic-ios#1 Co-authored-by: fmodf <fmodf.ios@gmail.com> Co-committed-by: fmodf <fmodf.ios@gmail.com>
70 lines
2.1 KiB
Swift
70 lines
2.1 KiB
Swift
import SwiftUI
|
|
|
|
struct ContactsPickerView: View {
|
|
@Environment(\.router) var router
|
|
@EnvironmentObject var messages: MessagesStore
|
|
|
|
@State private var rosters: [Roster] = []
|
|
@State private var selectedContact: Roster?
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
// Contacts list
|
|
if !rosters.isEmpty {
|
|
List {
|
|
ForEach(rosters) { roster in
|
|
ContactRow(roster: roster, selectedContact: $selectedContact)
|
|
}
|
|
}
|
|
.listStyle(.plain)
|
|
.background(Color.Material.Background.light)
|
|
} else {
|
|
Spacer()
|
|
}
|
|
|
|
// 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 {
|
|
if let selectedContact = selectedContact {
|
|
messages.sendContact(selectedContact.contactBareJid)
|
|
router.dismissEnvironment()
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
rosters = await Roster.allActive
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct ContactRow: View {
|
|
var roster: Roster
|
|
@Binding var selectedContact: Roster?
|
|
|
|
var body: some View {
|
|
SharedListRow(
|
|
iconType: .charCircle(roster.name?.firstLetter ?? roster.contactBareJid.firstLetter),
|
|
text: roster.contactBareJid
|
|
)
|
|
.onTapGesture {
|
|
selectedContact = roster
|
|
}
|
|
}
|
|
}
|