Multiple images upload
This commit is contained in:
@@ -115,7 +115,7 @@ struct MediaPicker: UIViewControllerRepresentable {
|
|||||||
|
|
||||||
func makeUIViewController(context: Context) -> PHPickerViewController {
|
func makeUIViewController(context: Context) -> PHPickerViewController {
|
||||||
var configuration = PHPickerConfiguration(photoLibrary: .shared())
|
var configuration = PHPickerConfiguration(photoLibrary: .shared())
|
||||||
configuration.selectionLimit = 1
|
configuration.selectionLimit = 0 // Allows multiple media selection
|
||||||
configuration.filter = imagesOnly ? .images : .any(of: [.images, .videos])
|
configuration.filter = imagesOnly ? .images : .any(of: [.images, .videos])
|
||||||
|
|
||||||
let picker = PHPickerViewController(configuration: configuration)
|
let picker = PHPickerViewController(configuration: configuration)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ struct PostView: View {
|
|||||||
@State var newCursorIndex: Int?
|
@State var newCursorIndex: Int?
|
||||||
@State var textHeight: CGFloat? = nil
|
@State var textHeight: CGFloat? = nil
|
||||||
|
|
||||||
@State var preUploadedMedia: PreUploadedMedia? = nil
|
@State var preUploadedMedia: [PreUploadedMedia] = []
|
||||||
|
|
||||||
@StateObject var image_upload: ImageUploadModel = ImageUploadModel()
|
@StateObject var image_upload: ImageUploadModel = ImageUploadModel()
|
||||||
@StateObject var tagModel: TagModel = TagModel()
|
@StateObject var tagModel: TagModel = TagModel()
|
||||||
@@ -151,6 +151,7 @@ struct PostView: View {
|
|||||||
|
|
||||||
var ImageButton: some View {
|
var ImageButton: some View {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
|
preUploadedMedia.removeAll()
|
||||||
attach_media = true
|
attach_media = true
|
||||||
}, label: {
|
}, label: {
|
||||||
Image("images")
|
Image("images")
|
||||||
@@ -445,16 +446,20 @@ struct PostView: View {
|
|||||||
.background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all))
|
.background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all))
|
||||||
.sheet(isPresented: $attach_media) {
|
.sheet(isPresented: $attach_media) {
|
||||||
MediaPicker(image_upload_confirm: $image_upload_confirm){ media in
|
MediaPicker(image_upload_confirm: $image_upload_confirm){ media in
|
||||||
self.preUploadedMedia = media
|
self.preUploadedMedia.append(media)
|
||||||
}
|
}
|
||||||
.alert(NSLocalizedString("Are you sure you want to upload this media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
|
.alert(NSLocalizedString("Are you sure you want to upload the selected media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
|
||||||
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
|
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
|
||||||
if let mediaToUpload = generateMediaUpload(preUploadedMedia) {
|
for media in preUploadedMedia {
|
||||||
self.handle_upload(media: mediaToUpload)
|
if let mediaToUpload = generateMediaUpload(media) {
|
||||||
self.attach_media = false
|
self.handle_upload(media: mediaToUpload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
self.attach_media = false
|
||||||
|
}
|
||||||
|
Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {
|
||||||
|
preUploadedMedia.removeAll()
|
||||||
}
|
}
|
||||||
Button(NSLocalizedString("Cancel", comment: "Button to cancel the upload."), role: .cancel) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $attach_camera) {
|
.sheet(isPresented: $attach_camera) {
|
||||||
@@ -486,6 +491,7 @@ struct PostView: View {
|
|||||||
if isEmpty() {
|
if isEmpty() {
|
||||||
clear_draft()
|
clear_draft()
|
||||||
}
|
}
|
||||||
|
preUploadedMedia.removeAll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user