another.im-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPickerView.swift
2024-08-19 09:03:15 +02:00

53 lines
1.7 KiB
Swift

import AVFoundation
import MobileCoreServices
import Photos
import SwiftUI
struct MediaPickerView: View {
@Environment(\.router) var router
@EnvironmentObject var attachments: AttachmentsStore
@State private var selectedItems: [String] = []
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
CameraCellPreview()
// For gallery
GalleryView(selectedItems: $selectedItems)
}
}
// 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 {
let items = attachments.galleryItems.filter { selectedItems.contains($0.id) }
attachments.sendMedia(items)
router.dismissEnvironment()
}
}
}
}