![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
fitbit-gestures
Advanced tools
This library allows you to detect different gestures in Fitbit devices. Tested only on Fitbit SDK 5.0
Install the library with npm i fitbit-gestures
or yarn add fitbit-gestures
Tap, Double Tap, Long Press, Swipe, Slide
You must provide an Element or the ID of an existing element.
The selected element should have "pointer-events" set to "visible". Will work only on elements which can have this attribute, like RectElements.
<svg>
<rect id="detectorElement" pointer-events="visible" />
</svg>
Warning
Keep in mind that only one gesture listener can be attached to each element. Attaching multiple detectors to the same element will overwrite the previous ones.
For some gestures, you can customize the detectors. View Single Gesture configuration below.
import { GestureDetector, GestureEvent } from 'fitbit-gestures';
// Get the element. You can also pass the element ID
const element = document.getElementById('detectorElement');
const detector = new GestureDetector(element)
.onTap((event: GestureEvent) => {
//Do something
})
.onDoubleTap((event: GestureEvent) => {
//Do something
})
.onLongPress((event: GestureEvent) => {
//Do something
})
.onSlide((event: GestureEvent) => {
//Do something
})
.onSwipe((event: GestureEvent) => {
//Do something
});
All detectors will return a GestureEvent in the callback function
interface GestureEvent {
type: GestureType,
point: Point,
from?: Point, //Swipe & Slide only
dir?: GestureDirection, //Swipe only
status?: GestureStatus //Slide only
}
interface Point {
x: number,
y: number
}
enum GestureType {
Tap = 'Tap',
DoubleTap = 'DoubleTap',
LongPress = 'LongPress',
Slide = 'Slide',
Swipe = 'Swipe'
}
enum GestureDirection {
Up = 'Up',
Down = 'Down',
Left = 'Left',
Right = 'Right'
}
enum GestureStatus {
Started = 'Started',
Moved = 'Moved',
Ended = 'Ended'
}
If you only need one type of gesture on an element, it will be slightly faster to use a dedicated class for that.
//Optional configurations
const swipeConfig: SwipeConfig = {
threshold: 100
};
const doubleTapConfig: DoubleTapConfig = {
interval: 250
}
const longPressConfig: LongPressConfig = {
time: 300,
threshold: 10
}
const tap = new TapDetector('tapElement', onGesture.bind(this));
const doubleTap = new DoubleTapDetector('doubleTapElement', onGesture.bind(this), doubleTapConfig);
const longPress = new LongPressDetector('longPressElement', onGesture.bind(this));
const slide = new SlideDetector('slideElement', onGesture.bind(this));
const swipe = new SwipeDetector('swipeElement', onGesture.bind(this), swipeConfig);
function onGesture(event: GestureEvent) {
if(event.type === GestureType.Swipe && event.dir === GestureDirection.Down) {
//Do something
} else if(event.type === GestureType.Slide) {
//Do something
}
}
Attribute | Description | Default |
---|---|---|
threshold | Minimum distance (in pixels) required to trigger the event | 100px |
Attribute | Description | Default |
---|---|---|
interval | Time (in ms) required to trigger the event | 250ms |
Attribute | Description | Default |
---|---|---|
time | Minimum time (in ms) required to trigger the event | 300ms |
threshold | Max distance (in px) allowed | 10px |
FAQs
Library to detect gestures on Fitbit devices
The npm package fitbit-gestures receives a total of 0 weekly downloads. As such, fitbit-gestures popularity was classified as not popular.
We found that fitbit-gestures demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.