feat: show loading indicator when photo is being loaded

This commit is contained in:
dscyrescotti
2024-06-24 21:23:42 +07:00
parent cfa177f3f3
commit a2ed7c43bb
3 changed files with 9 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ public class Tool: NSObject, ObservableObject {
@Published var draggedPen: Pen?
// MARK: - Photo
@Published var selectedPhotoItem: PhotoItem?
@Published var isLoadingPhoto: Bool = false
@Published var selection: ToolSelection = .hand
@@ -120,6 +121,7 @@ public class Tool: NSObject, ObservableObject {
func selectPhoto(_ image: UIImage, for canvasID: NSManagedObjectID) {
guard let (resizedImage, dimension) = resizePhoto(of: image) else { return }
let photoItem = bookmarkPhoto(of: resizedImage, in: dimension, with: canvasID)
isLoadingPhoto = false
withAnimation {
selectedPhotoItem = photoItem
}

View File

@@ -46,7 +46,7 @@ struct MemoView: View {
.overlay(alignment: .bottomLeading) {
zoomControl
}
.disabled(textFieldState)
.disabled(textFieldState || tool.isLoadingPhoto)
.overlay(alignment: .top) {
Toolbar(size: size, memo: memo, tool: tool, canvas: canvas, history: history)
}
@@ -61,6 +61,11 @@ struct MemoView: View {
EmptyView()
}
}
.overlay {
if tool.isLoadingPhoto {
loadingIndicator("Loading photo...")
}
}
}
@ViewBuilder

View File

@@ -62,6 +62,7 @@ struct Toolbar: View {
.onChange(of: photosPickerItem) { oldValue, newValue in
if newValue != nil {
Task {
tool.isLoadingPhoto = true
let data = try? await newValue?.loadTransferable(type: Data.self)
if let data, let image = UIImage(data: data) {
tool.selectPhoto(image, for: canvas.canvasID)