feat: allow multiple photo selection

This commit is contained in:
dscyrescotti
2024-07-20 17:42:01 +07:00
parent eee1cbe01b
commit a8ea08f63d
@@ -21,7 +21,7 @@ struct PhotoDock: View {
@State private var opensCamera: Bool = false @State private var opensCamera: Bool = false
@State private var isCameraAccessDenied: Bool = false @State private var isCameraAccessDenied: Bool = false
@State private var photosPickerItem: PhotosPickerItem? @State private var photosPickerItems: [PhotosPickerItem] = []
init(memo: MemoObject, tool: Tool, canvas: Canvas) { init(memo: MemoObject, tool: Tool, canvas: Canvas) {
self.memo = memo self.memo = memo
@@ -80,12 +80,14 @@ struct PhotoDock: View {
Text("Memola requires access to the camera to capture photos. Please open Settings and enable camera access.") Text("Memola requires access to the camera to capture photos. Please open Settings and enable camera access.")
} }
#endif #endif
.onChange(of: photosPickerItem) { oldValue, newValue in .onChange(of: photosPickerItems) { oldValue, newValue in
if let photoItem = newValue { if !newValue.isEmpty {
Task { Task {
tool.isLoadingPhoto = true tool.isLoadingPhoto = true
await createFile(for: photoItem) for photoItem in newValue {
photosPickerItem = nil await createFile(for: photoItem)
}
photosPickerItems = []
tool.isLoadingPhoto = false tool.isLoadingPhoto = false
} }
} }
@@ -105,7 +107,7 @@ struct PhotoDock: View {
} }
.hoverEffect(.lift) .hoverEffect(.lift)
#endif #endif
PhotosPicker(selection: $photosPickerItem, matching: .images, preferredItemEncoding: .compatible) { PhotosPicker(selection: $photosPickerItems, matching: .images, preferredItemEncoding: .compatible) {
Image(systemName: "photo.fill.on.rectangle.fill") Image(systemName: "photo.fill.on.rectangle.fill")
#if os(macOS) #if os(macOS)
.frame(width: size * 2, height: size) .frame(width: size * 2, height: size)
@@ -161,7 +163,7 @@ struct PhotoDock: View {
} }
.hoverEffect(.lift) .hoverEffect(.lift)
#endif #endif
PhotosPicker(selection: $photosPickerItem, matching: .images, preferredItemEncoding: .compatible) { PhotosPicker(selection: $photosPickerItems, matching: .images, preferredItemEncoding: .compatible) {
Image(systemName: "photo.fill.on.rectangle.fill") Image(systemName: "photo.fill.on.rectangle.fill")
.frame(width: size, height: size) .frame(width: size, height: size)
.clipShape(.rect(cornerRadius: 8)) .clipShape(.rect(cornerRadius: 8))