I want to drag the image along y-axis. It seems quite simple. However I put the "offset" following the "gesture" by mistake. Then cpu runs at full speed and UI becomes irresponsive.
Everything is ok by reordering "offset" before "gesture". But I can't figure it out.
"DragEffectViewModifier-ondrag" displays on the console repeatedly. What leads to the "cycle behavior"? It makes cpu to run at full speed and UI to become irresponsive when "offset" placed below "gesture"
struct ContentView: View {
@State private var currentPosition: CGSize = .zero
@State private var newPosition: CGSize = .zero
var body: some View {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
// .offset(x: currentPosition.width, y: currentPosition.height)
.gesture(DragGesture()
.onChanged { value in
print("DragEffectViewModifier-ondrag")
currentPosition = CGSize(width: 0, height: value.translation.height + newPosition.height)
}
.onEnded { value in
newPosition = currentPosition
})
.offset(x: currentPosition.width, y: currentPosition.height)
}
}