pub struct DragValue {
pub location: (f64, f64),
pub start_location: (f64, f64),
pub velocity: (f64, f64),
pub time: f64,
}Expand description
A DragGesture.Value, read out of the struct SwiftUI hands the handler.
on_drag_gesture used to throw this away — the handler was () -> () and
the value went into invoke_value_action, which ignores its argument. A
drag handler that cannot see where the drag went is not much of a drag
handler: it can tell you that something was dragged and nothing else.
The fields come from the struct’s own layout rather than from accessors,
because SwiftUI exports exactly one — translation — and none of the
others:
+0 time Date (seconds from the 2001 epoch)
+8 location CGPoint
+24 startLocation CGPoint
+40 _velocity _Velocity<CGSize>
+56 platform (empty)That layout is read from the metadata at run time rather than trusted: a
field added in front of location in a later SwiftUI would otherwise turn
every drag into silent nonsense. If the shape is not the five fields above,
the reader hands back zeroes rather than reading somewhere it should not.
Fields§
§location: (f64, f64)Where the drag is now, in the gesture’s coordinate space.
start_location: (f64, f64)Where it began.
velocity: (f64, f64)How fast it was moving, in points per second.
_Velocity<CGSize> wraps a single CGSize and nothing else — checked
by following the field record’s symbolic reference to the descriptor,
which reports one stored field — so the two doubles at the field’s own
offset are the velocity, with no wrapper to step over.
time: f64Seconds since Apple’s reference date (1 January 2001), which is what a
Date stores. Useful for comparing two values, not as a wall clock.