another.im-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/MediaPickerView.swift

56 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
@EnvironmentObject var store: AttachmentsStore
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-17 16:15:05 +00:00
Task {
let items = store.galleryItems.filter { selectedItems.contains($0.id) }
await conversation.sendMedia(items)
}
router.dismissEnvironment()
2024-08-17 08:50:44 +00:00
}
}
}
}