161 lines
6.4 KiB
Swift
161 lines
6.4 KiB
Swift
import AVFoundation
|
|
import MobileCoreServices
|
|
import Photos
|
|
import SwiftUI
|
|
|
|
struct MediaPickerView: View {
|
|
// @State private var showCameraPicker = false
|
|
// @State private var cameraReady = false
|
|
|
|
@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
|
|
// if store.state.sharingState.isGalleryAccessGranted {
|
|
// ForEach(store.state.sharingState.galleryItems) { item in
|
|
// GridViewItem(item: item, selected: $selectedItems)
|
|
// }
|
|
// } else {
|
|
// Button {
|
|
// openAppSettings()
|
|
// } label: {
|
|
// ZStack {
|
|
// Rectangle()
|
|
// .fill(Color.Material.Background.light)
|
|
// .overlay {
|
|
// VStack {
|
|
// Image(systemName: "photo")
|
|
// .foregroundColor(.Material.Elements.active)
|
|
// .font(.system(size: 30))
|
|
// Text("Allow gallery access")
|
|
// .foregroundColor(.Material.Text.main)
|
|
// .font(.body3)
|
|
// }
|
|
// }
|
|
// .frame(height: 100)
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
// .fullScreenCover(isPresented: $showCameraPicker) {
|
|
// CameraPicker(sourceType: .camera) { data, type in
|
|
// store.dispatch(.sharingAction(.cameraCaptured(media: data, type: type)))
|
|
// showCameraPicker = false
|
|
// store.dispatch(.sharingAction(.showSharing(false)))
|
|
// }
|
|
// .edgesIgnoringSafeArea(.all)
|
|
// }
|
|
|
|
// 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 {
|
|
// store.dispatch(.sharingAction(.shareMedia(ids: selectedItems)))
|
|
// store.dispatch(.sharingAction(.showSharing(false)))
|
|
}
|
|
}
|
|
// .onAppear {
|
|
// store.dispatch(.sharingAction(.checkCameraAccess))
|
|
// store.dispatch(.sharingAction(.checkGalleryAccess))
|
|
// }
|
|
// .onChange(of: store.state.sharingState.isGalleryAccessGranted) { granted in
|
|
// if granted {
|
|
// store.dispatch(.fileAction(.fetchItemsFromGallery))
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
|
|
private struct GridViewItem: View {
|
|
// let item: SharingGalleryItem
|
|
@Binding var selected: [String]
|
|
@State var isSelected = false
|
|
|
|
var body: some View {
|
|
Text("Test")
|
|
// if let data = item.thumbnail {
|
|
// ZStack {
|
|
// Image(uiImage: UIImage(data: data) ?? UIImage())
|
|
// .resizable()
|
|
// .aspectRatio(contentMode: .fill)
|
|
// .frame(width: Const.galleryGridSize, height: Const.galleryGridSize)
|
|
// .clipped()
|
|
// if let duration = item.duration {
|
|
// VStack {
|
|
// Spacer()
|
|
// HStack {
|
|
// Spacer()
|
|
// Text(duration)
|
|
// .foregroundColor(.Material.Text.white)
|
|
// .font(.sub1)
|
|
// .shadow(color: .black, radius: 2)
|
|
// .padding(4)
|
|
// }
|
|
// }
|
|
// }
|
|
// if isSelected {
|
|
// VStack {
|
|
// HStack {
|
|
// Spacer()
|
|
// Circle()
|
|
// .frame(width: 30, height: 30)
|
|
// .shadow(color: .black, radius: 2)
|
|
// .foregroundColor(.Material.Shape.white)
|
|
// .overlay {
|
|
// Image(systemName: "checkmark")
|
|
// .foregroundColor(.Material.Elements.active)
|
|
// .font(.body3)
|
|
// }
|
|
// .padding(4)
|
|
// }
|
|
// Spacer()
|
|
// }
|
|
// }
|
|
// }
|
|
// .onTapGesture {
|
|
// isSelected.toggle()
|
|
// if isSelected {
|
|
// selected.append(item.id)
|
|
// } else {
|
|
// selected.removeAll { $0 == item.id }
|
|
// }
|
|
// }
|
|
// } else {
|
|
// ZStack {
|
|
// Rectangle()
|
|
// .fill(Color.Material.Background.light)
|
|
// .overlay {
|
|
// ProgressView()
|
|
// .foregroundColor(.Material.Elements.active)
|
|
// }
|
|
// .frame(width: Const.galleryGridSize, height: Const.galleryGridSize)
|
|
// }
|
|
// }
|
|
}
|
|
}
|