conversations-classic-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift

54 lines
1.8 KiB
Swift
Raw Normal View History

2024-08-17 08:50:44 +00:00
import AVFoundation
import MobileCoreServices
import Photos
import SwiftUI
struct MediaPickerView: View {
2024-08-17 16:15:05 +00:00
@Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore
2024-08-18 09:05:43 +00:00
@EnvironmentObject var attachments: AttachmentsStore
2024-08-17 16:15:05 +00:00
2024-08-17 10:39:40 +00:00
@State private var selectedItems: [String] = []
2024-08-17 08:50:44 +00:00
var body: some View {
let columns = Array(repeating: GridItem(.flexible(), spacing: 0), count: 3)
VStack(spacing: 0) {
// List of media
ScrollView(showsIndicators: false) {
LazyVGrid(columns: columns, spacing: 0) {
// For camera
2024-08-17 10:39:40 +00:00
CameraCellPreview()
2024-08-17 08:50:44 +00:00
// For gallery
2024-08-17 13:54:54 +00:00
GalleryView(selectedItems: $selectedItems)
2024-08-17 08:50:44 +00:00
}
}
// Send panel
Rectangle()
.foregroundColor(.Material.Shape.black)
.frame(maxWidth: .infinity)
.frame(height: self.selectedItems.isEmpty ? 0 : 50)
.overlay {
HStack {
Text(L10n.Attachment.Send.media)
.foregroundColor(.Material.Text.white)
.font(.body1)
Image(systemName: "arrow.up.circle")
.foregroundColor(.Material.Text.white)
.font(.body1)
.padding(.leading, 8)
}
.padding()
}
.clipped()
.onTapGesture {
2024-08-18 10:26:54 +00:00
let items = attachments.galleryItems.filter { selectedItems.contains($0.id) }
attachments.sendMedia(items)
2024-08-17 16:15:05 +00:00
router.dismissEnvironment()
2024-08-17 08:50:44 +00:00
}
}
}
}