pub struct GestureValue<V: GestureData = ()> { /* private fields */ }Expand description
A built Gesture — its bytes, its type, and the type its handlers see.
The Value is carried because onChanged needs it: that extension is
constrained to Value: Equatable and takes the witness as an argument, so
a gesture that does not know its own value type cannot be given a changed
handler. onEnded does not need it, which is why the first bindings could
get by without.
Dropping one does not destroy the Swift value. Every gesture this module
builds is a plain aggregate of scalars — DragGesture is a CGFloat and a
coordinate space, TapGesture an Int — and the combinators wrap those
without adding a reference. The closures are a different matter: they are
leaked on purpose, because SwiftUI stores them.
Implementations§
Source§impl<V: GestureData> GestureValue<V>
impl<V: GestureData> GestureValue<V>
Sourcepub fn on_ended(self, action: impl Fn(V) + 'static) -> GestureValue<V>
pub fn on_ended(self, action: impl Fn(V) + 'static) -> GestureValue<V>
Gesture.onEnded(_:) — run action when the gesture completes.
Returns _EndedGesture<Self>, which is itself a Gesture, so these
chain the way they do in Swift.
Sourcepub fn on_changed(self, action: impl Fn(V) + 'static) -> GestureValue<V>
pub fn on_changed(self, action: impl Fn(V) + 'static) -> GestureValue<V>
Gesture.onChanged(_:) — run action every time the value moves.
This is a different extension from GestureValue::on_ended,
constrained to Value: Equatable, so it takes that witness as a sixth
argument and returns _ChangedGesture. A gesture whose value has no
metadata here — a tap, whose value is Void — cannot have one, and
says so rather than building something that would not fire.
Source§impl<V: GestureData> GestureValue<V>
impl<V: GestureData> GestureValue<V>
Sourcepub fn sequenced<W: GestureData>(
self,
other: GestureValue<W>,
) -> GestureValue<()>
pub fn sequenced<W: GestureData>( self, other: GestureValue<W>, ) -> GestureValue<()>
Gesture.sequenced(before:) — this one, then the other.
A long press that has to complete before a drag begins is the shape
this exists for: long_press(0.5, 10.0).sequenced(drag(0.0)).
Sourcepub fn exclusively<W: GestureData>(
self,
other: GestureValue<W>,
) -> GestureValue<()>
pub fn exclusively<W: GestureData>( self, other: GestureValue<W>, ) -> GestureValue<()>
Gesture.exclusively(before:) — whichever recognises first wins.
Sourcepub fn simultaneously<W: GestureData>(
self,
other: GestureValue<W>,
) -> GestureValue<()>
pub fn simultaneously<W: GestureData>( self, other: GestureValue<W>, ) -> GestureValue<()>
Gesture.simultaneously(with:) — both may recognise at once.