I’m engaged on a customized button part for which I want to make use of drag gesture to set numerous states of customized animation, beneath is simplified code of the place I’m in the intervening time. Downside right here is that motion related to the button will get executed throughout .onEnded
section. Which means consumer can drag their finger outdoors of the button and upon releasing it motion might be known as. I might wish to detect if finger is in bounds of the button one way or the other and if consumer drags it out, not execute motion and toggle taping state to off, primarily canceling the faucet when finger is just not on the button.
I attempted wrapping GeometryReader
round my HStack
, but it surely reported bizarre values (a lot greater values than what the actual dimension of the button is) and it made button part increase to full display width and top.
HStack {
Textual content("Pattern Textual content")
}
.scaleEffect(taping ? 0.9 : 1)
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { pressed in
taping.toggle()
}
.onEnded { pressed in
taping.toggle()
// Execute faucet motion right here
}
)