mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-25 10:51:41 +01:00
feat: show loading indicator when photo is being loaded
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user