From 21b4e772d80e427361c891bc0d17ee81e64d929c Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 2 Jul 2024 11:56:27 +0200 Subject: [PATCH] wip --- .../Resources/Strings/Localizable.strings | 8 ++ .../View/Screens/AttachmentPickerScreen.swift | 16 ---- .../AttachmentContactsPickerView.swift | 8 ++ .../AttachmentFilesPickerView.swift | 48 +++++++++++ .../Attachments/AttachmentHeader.swift | 29 +++++++ .../AttachmentLocationPickerView.swift | 44 ++++++++++ .../AttachmentMediaPickerView.swift | 62 ++++++++++++++ .../Attachments/AttachmentPickerScreen.swift | 27 ++++++ .../Attachments/AttachmentTabBar.swift | 85 +++++++++++++++++++ 9 files changed, 311 insertions(+), 16 deletions(-) delete mode 100644 ConversationsClassic/View/Screens/AttachmentPickerScreen.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentPickerScreen.swift create mode 100644 ConversationsClassic/View/Screens/Attachments/AttachmentTabBar.swift diff --git a/ConversationsClassic/Resources/Strings/Localizable.strings b/ConversationsClassic/Resources/Strings/Localizable.strings index d0a1d7d..35b879b 100644 --- a/ConversationsClassic/Resources/Strings/Localizable.strings +++ b/ConversationsClassic/Resources/Strings/Localizable.strings @@ -58,3 +58,11 @@ "ServerConnectingIndicator.State.connecting" = "Connecting to server"; "ServerConnectingIndicator.State.connected" = "Connected"; "ServerConnectingIndicator.State.error" = "Server unreachable. Check internet connection and server name"; + +// MARK: Attachments +"Attachment.Prompt.main" = "Select attachment"; +"Attachment.Tab.media" = "Media"; +"Attachment.Tab.files" = "Files"; +"Attachment.Tab.location" = "Location"; +"Attachment.Tab.contacts" = "Contacts"; + diff --git a/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift b/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift deleted file mode 100644 index 9bf47f3..0000000 --- a/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift +++ /dev/null @@ -1,16 +0,0 @@ -import SwiftUI - -struct AttachmentPickerScreen: View { - @EnvironmentObject var store: AppStore - - var body: some View { - VStack { - Button { - store.dispatch(.conversationAction(.showAttachmentPicker(false))) - } label: { - Text("Back") - } - Text("Do It") - } - } -} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift new file mode 100644 index 0000000..a532814 --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift @@ -0,0 +1,8 @@ +import SwiftUI + +struct AttachmentContactsPickerView: View { + var body: some View { + Text("Contact Picker") + // Implement your contact picker here + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift new file mode 100644 index 0000000..2777e50 --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift @@ -0,0 +1,48 @@ +import SwiftUI +import UIKit + +struct AttachmentFilesPickerView: View { + @State private var isPickerPresented = false + + var body: some View { + Button(action: { + isPickerPresented = true + }) { + Text("Select Files") + } + .sheet(isPresented: $isPickerPresented) { + DocumentPicker() + } + } +} + +struct DocumentPicker: UIViewControllerRepresentable { + func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIDocumentPickerViewController { + let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) + picker.delegate = context.coordinator + picker.allowsMultipleSelection = true + return picker + } + + func updateUIViewController(_: UIDocumentPickerViewController, context _: UIViewControllerRepresentableContext) {} + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject, UIDocumentPickerDelegate { + var parent: DocumentPicker + + init(_ parent: DocumentPicker) { + self.parent = parent + } + + func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) { + // Handle the selected files + } + + func documentPickerWasCancelled(_: UIDocumentPickerViewController) { + // Handle cancellation + } + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift new file mode 100644 index 0000000..e36e0ff --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentHeader.swift @@ -0,0 +1,29 @@ +import SwiftUI + +struct AttachmentHeader: View { + @EnvironmentObject var store: AppStore + + var body: some View { + ZStack { + // bg + Color.Main.backgroundDark + .ignoresSafeArea() + + // title + Text(L10n.Attachment.Prompt.main) + .font(.head2) + .foregroundColor(Color.Main.black) + + HStack { + Spacer() + Image(systemName: "xmark") + .foregroundColor(Color.Tango.orangeMedium) + .tappablePadding(.symmetric(12)) { + store.dispatch(.conversationAction(.showAttachmentPicker(false))) + } + } + .padding(.horizontal, 16) + } + .frame(height: 44) + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift new file mode 100644 index 0000000..3ed9c4d --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -0,0 +1,44 @@ +import MapKit +import SwiftUI +import UIKit + +struct AttachmentLocationPickerView: View { + @State private var region = MKCoordinateRegion( + center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868), + span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) + ) + + var body: some View { + MapView(coordinateRegion: $region) + } +} + +struct MapView: UIViewRepresentable { + @Binding var coordinateRegion: MKCoordinateRegion + + func makeUIView(context: Context) -> MKMapView { + let mapView = MKMapView() + mapView.delegate = context.coordinator + return mapView + } + + func updateUIView(_ uiView: MKMapView, context _: Context) { + uiView.setRegion(coordinateRegion, animated: true) + } + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject, MKMapViewDelegate { + var parent: MapView + + init(_ parent: MapView) { + self.parent = parent + } + + func mapView(_ mapView: MKMapView, regionDidChangeAnimated _: Bool) { + parent.coordinateRegion = mapView.region + } + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift new file mode 100644 index 0000000..bf3df4d --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift @@ -0,0 +1,62 @@ +import SwiftUI +import UIKit + +struct AttachmentMediaPickerView: View { + @State private var isPickerPresented = false + @State private var mediaType: UIImagePickerController.SourceType = .photoLibrary + + var body: some View { + VStack { + Button(action: { + mediaType = .photoLibrary + isPickerPresented = true + }) { + Text("Select from Photo Library") + } + + Button(action: { + mediaType = .camera + isPickerPresented = true + }) { + Text("Take Photo or Video") + } + } + .sheet(isPresented: $isPickerPresented) { + ImagePicker(sourceType: mediaType) + } + } +} + +struct ImagePicker: UIViewControllerRepresentable { + var sourceType: UIImagePickerController.SourceType + + func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIImagePickerController { + let picker = UIImagePickerController() + picker.sourceType = sourceType + picker.allowsEditing = true + picker.delegate = context.coordinator + return picker + } + + func updateUIViewController(_: UIImagePickerController, context _: UIViewControllerRepresentableContext) {} + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { + var parent: ImagePicker + + init(_ parent: ImagePicker) { + self.parent = parent + } + + func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo _: [UIImagePickerController.InfoKey: Any]) { + // Handle the selected media + } + + func imagePickerControllerDidCancel(_: UIImagePickerController) { + // Handle cancellation + } + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentPickerScreen.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentPickerScreen.swift new file mode 100644 index 0000000..1ca9083 --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentPickerScreen.swift @@ -0,0 +1,27 @@ +import SwiftUI + +struct AttachmentPickerScreen: View { + @EnvironmentObject var store: AppStore + + @State private var selectedTab: AttachmentTab = .media + + var body: some View { + ZStack { + // Background color + Color.Main.backgroundLight + .ignoresSafeArea() + + // Content + VStack(spacing: 0) { + // Header + AttachmentHeader() + + // Pickers + Spacer() + + // Tab bar + AttachmentTabBar(selectedTab: $selectedTab) + } + } + } +} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentTabBar.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentTabBar.swift new file mode 100644 index 0000000..3f86cf8 --- /dev/null +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentTabBar.swift @@ -0,0 +1,85 @@ +import SwiftUI + +enum AttachmentTab: Int, CaseIterable { + case media + case files + case location + case contacts +} + +struct AttachmentTabBar: View { + @Binding var selectedTab: AttachmentTab + + var body: some View { + VStack(spacing: 0) { + Rectangle() + .frame(maxWidth: .infinity) + .frame(height: 0.2) + .foregroundColor(.Main.separator) + HStack(spacing: 0) { + AttachmentTabBarButton(tab: .media, selected: $selectedTab) + AttachmentTabBarButton(tab: .files, selected: $selectedTab) + AttachmentTabBarButton(tab: .location, selected: $selectedTab) + AttachmentTabBarButton(tab: .contacts, selected: $selectedTab) + } + .background(Color.Main.backgroundDark) + } + .frame(height: 50) + } +} + +private struct AttachmentTabBarButton: View { + let tab: AttachmentTab + @Binding var selected: AttachmentTab + + var body: some View { + ZStack { + VStack(spacing: 2) { + buttonImg + .foregroundColor(selected == tab ? .Material.greenDark500 : .Main.gray) + .font(.system(size: 24, weight: .light)) + .symbolRenderingMode(.hierarchical) + Text(buttonTitle) + .font(.sub1) + .foregroundColor(selected == tab ? .Main.black : .Main.gray) + } + Rectangle() + .foregroundColor(.white.opacity(0.01)) + .onTapGesture { + selected = tab + } + } + } + + var buttonImg: Image { + switch tab { + case .media: + return Image(systemName: "photo.on.rectangle.angled") + + case .files: + return Image(systemName: "doc.on.doc") + + case .location: + return Image(systemName: "location.circle") + + case .contacts: + return Image(systemName: "person.crop.circle") + } + } + + var buttonTitle: String { + switch tab { + case .media: + return L10n.Attachment.Tab.media + + case .files: + return L10n.Attachment.Tab.files + + case .location: + return L10n.Attachment.Tab.location + + case .contacts: + return L10n.Attachment.Tab.contacts + } + } +}