|
|
|
@ -8,7 +8,12 @@ import SwiftUI |
|
|
|
|
|
|
|
struct SPhotoView : View { |
|
|
|
var completionHandler: ((Bool) -> Void)? |
|
|
|
@ObservedObject |
|
|
|
var model: SPhotoModel |
|
|
|
@State |
|
|
|
var update = false |
|
|
|
@State var scale: CGFloat = 1.0 |
|
|
|
@State var lastScaleValue: CGFloat = 1.0 |
|
|
|
|
|
|
|
var body: some View { |
|
|
|
VStack { |
|
|
|
@ -18,22 +23,45 @@ struct SPhotoView : View { |
|
|
|
completionHandler!(true) |
|
|
|
}, label: { |
|
|
|
Text("cancel") |
|
|
|
}) |
|
|
|
}).foregroundColor(update ? Color.yellow : Color.blue) |
|
|
|
.buttonStyle(BorderlessButtonStyle()) |
|
|
|
Spacer() |
|
|
|
} |
|
|
|
}.frame(height: 50) |
|
|
|
AsyncImage(item: model.allItems[model.index], thumb: false, placeholder: { Text("Loading ...") }, |
|
|
|
image: { Image(uiImage: $0).resizable() }) |
|
|
|
// AsyncImage(item: model.selectedItem, thumb: false, placeholder: { Text("Loading ...") }, image: { Image(uiImage: $0).resizable() }) |
|
|
|
SwiftUI.AsyncImage(url: URL(string: model.selectedItem.imageUrlAbsolute)){ image in |
|
|
|
image //.resizable();//.scaledToFit() |
|
|
|
} |
|
|
|
placeholder: { |
|
|
|
if let i = model.selectedItem.thumbImage { |
|
|
|
Image(uiImage: i) |
|
|
|
} |
|
|
|
else { |
|
|
|
ProgressView() |
|
|
|
} |
|
|
|
}.scaleEffect(scale) |
|
|
|
.gesture(MagnificationGesture() |
|
|
|
.onChanged { val in |
|
|
|
let delta = val / self.lastScaleValue |
|
|
|
self.lastScaleValue = val |
|
|
|
scale = self.scale * delta |
|
|
|
|
|
|
|
//... anything else e.g. clamping the newScale |
|
|
|
}.onEnded { val in |
|
|
|
// without this the next gesture will be broken |
|
|
|
self.lastScaleValue = 1.0 |
|
|
|
}) |
|
|
|
.contentShape(Rectangle()).clipped(); |
|
|
|
|
|
|
|
ScrollView(.horizontal, showsIndicators: false) { |
|
|
|
HStack { |
|
|
|
ForEach(model.allItems) { item in |
|
|
|
Button(action: { |
|
|
|
gotoSnapshot(item) |
|
|
|
}) { |
|
|
|
}, label: { |
|
|
|
AsyncImage(item: item, placeholder: { Text("Loading ...") }, |
|
|
|
image: { Image(uiImage: $0).resizable() }) |
|
|
|
} |
|
|
|
}).buttonStyle(BorderlessButtonStyle()) |
|
|
|
}.frame(height: 70) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -41,6 +69,9 @@ struct SPhotoView : View { |
|
|
|
} |
|
|
|
|
|
|
|
func gotoSnapshot(_ item: MediaItem) { |
|
|
|
model.selectedItem = item |
|
|
|
update.toggle() |
|
|
|
|
|
|
|
print("select \(model.selectedItem.imageUrlAbsolute)") |
|
|
|
} |
|
|
|
} |