vael-ui v0.5.7

Used with a component · SwipeToReveal

resolveSwipeCommit

Decides whether a released row opens or closes, as useSwipeReveal does. A flick faster than 0.11 px/ms opens when it moved toward open and closes when it moved away. A slower drag opens when more than half the panel shows. Use it to give a gesture of your own the same feel.

Install

import { resolveSwipeCommit } from 'vael-ui'

Examples

import { resolveSwipeCommit } from 'vael-ui'

// A panel of your own, released after a drag. `speed` is the release speed in px/ms, never negative.
function shouldOpen(speed: number, towardOpen: boolean, shown: number, width: number): boolean {
  return resolveSwipeCommit({ velocity: speed, towardOpen, openFraction: shown / width })
}

shouldOpen(0.3, true, 20, 100) // true: a quick flick toward open opens it
shouldOpen(0.3, false, 80, 100) // false: a quick flick toward closed closes it
shouldOpen(0.05, true, 40, 100) // false: a slow drag opens only past the halfway point
shouldOpen(0.05, false, 60, 100) // true: a slow drag past halfway stays open

Parameters

NameTypeDescription
velocitynumberThe drag speed in px/ms, never negative. useSwipeReveal passes the distance moved divided by the time since the press.
towardOpenbooleanWhether the drag moved toward the open side overall.
openFractionnumberHow far open the panel is at release, as a fraction of its width. It can go below 0 or above 1 while rubber-banding.

Returns

NameTypeDescription
returnbooleantrue to settle open, false to settle closed.