wip
This commit is contained in:
parent
21b4e772d8
commit
01f45af8f3
|
@ -1,28 +1,73 @@
|
|||
import AVFoundation
|
||||
import Photos
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
struct AttachmentMediaPickerView: View {
|
||||
@State private var isPickerPresented = false
|
||||
@State private var mediaType: UIImagePickerController.SourceType = .photoLibrary
|
||||
class MediaManager: ObservableObject {
|
||||
@Published var photos: [UIImage] = []
|
||||
@Published var cameraFeed: UIImage?
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Button(action: {
|
||||
mediaType = .photoLibrary
|
||||
isPickerPresented = true
|
||||
}) {
|
||||
Text("Select from Photo Library")
|
||||
init() {
|
||||
fetchPhotos()
|
||||
setupCameraFeed()
|
||||
}
|
||||
|
||||
private func fetchPhotos() {
|
||||
// let fetchOptions = PHFetchOptions()
|
||||
// fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
|
||||
// let assets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
|
||||
//
|
||||
// let manager = PHImageManager.default()
|
||||
// let option = PHImageRequestOptions()
|
||||
// option.isSynchronous = true
|
||||
//
|
||||
// assets.enumerateObjects { asset, _, _ in
|
||||
// manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option) { image, _ in
|
||||
// if let image = image {
|
||||
// DispatchQueue.main.async {
|
||||
// self.photos.append(image)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private func setupCameraFeed() {
|
||||
// Setup the camera feed and store the feed in the `cameraFeed` property
|
||||
}
|
||||
}
|
||||
|
||||
struct AttachmentMediaPickerView: View {
|
||||
@StateObject private var mediaManager = MediaManager()
|
||||
@State private var isPickerPresented = false
|
||||
@State private var selectedPhoto: UIImage?
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {
|
||||
if let cameraFeed = mediaManager.cameraFeed {
|
||||
Button(action: {
|
||||
mediaType = .camera
|
||||
isPickerPresented = true
|
||||
}) {
|
||||
Text("Take Photo or Video")
|
||||
Image(uiImage: cameraFeed)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
}
|
||||
}
|
||||
|
||||
ForEach(mediaManager.photos, id: \.self) { photo in
|
||||
Button(action: {
|
||||
selectedPhoto = photo
|
||||
}) {
|
||||
Image(uiImage: photo)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $isPickerPresented) {
|
||||
ImagePicker(sourceType: mediaType)
|
||||
ImagePicker(sourceType: .camera)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,19 @@ struct AttachmentPickerScreen: View {
|
|||
AttachmentHeader()
|
||||
|
||||
// Pickers
|
||||
Spacer()
|
||||
switch selectedTab {
|
||||
case .media:
|
||||
AttachmentMediaPickerView()
|
||||
|
||||
case .files:
|
||||
AttachmentFilesPickerView()
|
||||
|
||||
case .location:
|
||||
AttachmentLocationPickerView()
|
||||
|
||||
case .contacts:
|
||||
AttachmentContactsPickerView()
|
||||
}
|
||||
|
||||
// Tab bar
|
||||
AttachmentTabBar(selectedTab: $selectedTab)
|
||||
|
|
Loading…
Reference in a new issue