I have a Rec that I can move it in gesture action, but the problem is that gesture start capturing gesture in outside of its frame, which I expect just working inside the frame. here is the code and gif about issue:
gif:
code:
struct ContentView: View {
@State private var recLocation: CGFloat = CGFloat()
@GestureState private var recTranslation: CGFloat = CGFloat()
var body: some View {
GeometryReader { geometry in
Rectangle().fill(Color.red).frame(width: 50, height: 50, alignment: .center)
.position(x: recLocation + recTranslation + 25, y: geometry.size.height/2)
.gesture( DragGesture()
.updating($recTranslation) { value, state, translation in
state = value.translation.width
}
.onEnded { value in
recLocation = recLocation + value.translation.width
} )
}
}
}

