wip
This commit is contained in:
parent
21b4e772d8
commit
01f45af8f3
|
@ -1,28 +1,73 @@
|
||||||
|
import AVFoundation
|
||||||
|
import Photos
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
struct AttachmentMediaPickerView: View {
|
class MediaManager: ObservableObject {
|
||||||
@State private var isPickerPresented = false
|
@Published var photos: [UIImage] = []
|
||||||
@State private var mediaType: UIImagePickerController.SourceType = .photoLibrary
|
@Published var cameraFeed: UIImage?
|
||||||
|
|
||||||
var body: some View {
|
init() {
|
||||||
VStack {
|
fetchPhotos()
|
||||||
Button(action: {
|
setupCameraFeed()
|
||||||
mediaType = .photoLibrary
|
|
||||||
isPickerPresented = true
|
|
||||||
}) {
|
|
||||||
Text("Select from Photo Library")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: {
|
Button(action: {
|
||||||
mediaType = .camera
|
|
||||||
isPickerPresented = true
|
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) {
|
.sheet(isPresented: $isPickerPresented) {
|
||||||
ImagePicker(sourceType: mediaType)
|
ImagePicker(sourceType: .camera)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,19 @@ struct AttachmentPickerScreen: View {
|
||||||
AttachmentHeader()
|
AttachmentHeader()
|
||||||
|
|
||||||
// Pickers
|
// Pickers
|
||||||
Spacer()
|
switch selectedTab {
|
||||||
|
case .media:
|
||||||
|
AttachmentMediaPickerView()
|
||||||
|
|
||||||
|
case .files:
|
||||||
|
AttachmentFilesPickerView()
|
||||||
|
|
||||||
|
case .location:
|
||||||
|
AttachmentLocationPickerView()
|
||||||
|
|
||||||
|
case .contacts:
|
||||||
|
AttachmentContactsPickerView()
|
||||||
|
}
|
||||||
|
|
||||||
// Tab bar
|
// Tab bar
|
||||||
AttachmentTabBar(selectedTab: $selectedTab)
|
AttachmentTabBar(selectedTab: $selectedTab)
|
||||||
|
|
Loading…
Reference in a new issue