Primitives / foldkit-primitives/dom
Swipe
const · packages/primitives/src/dom/swipe.ts:138
const Swipe: Mount.MountDefinitionWithArgs<
'Swipe',
{
measure: Schema.optional<Schema.String>
slop: Schema.optional<Schema.Number>
scrolls: Schema.optional<Schema.Literals<readonly ['x', 'y']>>
touchOnly: Schema.optional<Schema.Boolean>
},
| {
readonly _tag: 'SwipeStarted'
readonly pointerId: number
readonly pointerType: string
readonly width: number
readonly height: number
}
| {
readonly _tag: 'Swiped'
readonly pointerId: number
readonly deltaX: number
readonly deltaY: number
}
| {
readonly _tag: 'SwipeEnded'
readonly pointerId: number
readonly deltaX: number
readonly deltaY: number
readonly velocityX: number
readonly velocityY: number
readonly completed: boolean
}
>Move with the speed of its release, for a gesture that a flick ends
(a sheet dragged to dismiss, a card swiped away): a primary-button pointer
down (or, given a slop, its first move past it) captures the pointer,
each move reports the delta from where it was pressed, and up reports the
last delta with the velocity over the last SWIPE_WINDOW milliseconds, by
the events' own time stamps. Cancel or lost capture ends it incomplete.
The start reports the size of what is moved, so a distance can be read as
a share of it. What a delta or a speed means is the parent's update.
Capture is released with the Mount.
Given scrolls, the element holds content that scrolls (a sheet's panel),
and a touch is followed by touch events, whose move can still refuse the
browser's scroll once the touch is under way, where a pointer's cannot:
past the slop, a touch that runs along the axis and finds nothing under it
that can scroll further its way swipes, and the browser scrolls any other.
A touch inside an element with a Swipe of its own (a handle in the panel)
is that one's, and none starts on a field or on data-no-swipe
(NO_SWIPE).
In the guides
- Find a primitive by taskPrimitives / foldkit-primitives
- Pressing and draggingPrimitives / Interaction
- Swiping and scrolling to restPrimitives / DOM