Skip to main content

GestureValue

Struct GestureValue 

Source
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>

Source

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.

Source

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>

Source

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)).

Source

pub fn exclusively<W: GestureData>( self, other: GestureValue<W>, ) -> GestureValue<()>

Gesture.exclusively(before:) — whichever recognises first wins.

Source

pub fn simultaneously<W: GestureData>( self, other: GestureValue<W>, ) -> GestureValue<()>

Gesture.simultaneously(with:) — both may recognise at once.

Auto Trait Implementations§

§

impl<V = ()> !Send for GestureValue<V>

§

impl<V = ()> !Sync for GestureValue<V>

§

impl<V> Freeze for GestureValue<V>
where PhantomData<fn(V)>: Freeze,

§

impl<V> RefUnwindSafe for GestureValue<V>

§

impl<V> Unpin for GestureValue<V>
where PhantomData<fn(V)>: Unpin,

§

impl<V> UnsafeUnpin for GestureValue<V>

§

impl<V> UnwindSafe for GestureValue<V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.