Since I can't edit my question, and the comments only allow in-line code I am going to post my other attempt at making this work using Apple's documented way (doesn't work either):
import SwiftUI
struct MovableResizableView<Content>: View where Content: View {
//@ObservedObject var imageModel: YearImageViewModel
@GestureState private var dragState = DragState.inactive
@GestureState private var scale: CGFloat = 1.0
@State var image = UIImage()
@State var width: CGFloat = 150
@State var height: CGFloat = 150
@State private var currentPosition: CGSize = .zero
@State private var newPosition: CGSize = .zero
@State private var isDragging = false
@State private var deleteBtn = false
@State private var deleted = false
var content: () -> Content
var body: some View {
content()
.opacity(dragState.isPressing ? 0.5 : 1.0)
.offset(x: dragState.translation.width + newPosition.width, y: dragState.translation.height + self.newPosition.height)
.animation(Animation.easeInOut(duration: 0.1), value: 0)
.gesture(LongPressGesture(minimumDuration: 1.0)
.sequenced(before: DragGesture())
.updating($dragState, body: { (value, state, transaction) in
switch value {
case .first(true):
state = .pressing
case .second(true, let drag):
state = .dragging(translation: drag?.translation ?? .zero)
default:
break
}
})
.onEnded({ (value) in
guard case .second(true, let drag?) = value else {
return
}
self.newPosition.height += drag.translation.height
self.newPosition.width += drag.translation.width
}))
.gesture(MagnificationGesture()
.updating($scale, body: { (value, scale, trans) in
scale = value.magnitude
}))
.scaleEffect(scale)
}
}
struct MovableResizableView_Previews: PreviewProvider {
static var previews: some View {
MovableResizableView() {
Image(systemName: "star.circle.fill")
.resizable()
.frame(width: 100, height: 100)
.foregroundColor(.green)
}
}
}