@freefugga/smooth-swipe-core
v0.1.2
Published
Shared types and motion math for smooth swipe buttons.
Readme
@freefugga/smooth-swipe-core
Shared core utilities for the Smooth Swipe Button packages by Nishidh Jain (@freefugga).
This package contains the shared:
- types
- default config
- threshold logic
- progress math
- render-state helpers
It is mainly intended for package internals, advanced integrations, or anyone building wrappers on top of the React and React Native packages.
Current shared behavior defaults:
- success threshold:
0.8 - spring reset: enabled by default in UI packages
- spring duration:
0.5seconds, capped at0.5
Install
npm install @freefugga/smooth-swipe-coreWhen To Use This Package
Use this package if you are:
- building your own swipe button wrapper
- sharing swipe logic across multiple UI adapters
- consuming the shared types in design-system code
If you just want a ready-to-use component, install one of these instead:
- React web:
@freefugga/react-smooth-swipe-button - React Native:
@freefugga/react-native-smooth-swipe-button
Usage
import {
DEFAULT_SWIPE_CONFIG,
clamp,
getMaxThumbX,
getProgress,
shouldComplete,
} from "@freefugga/smooth-swipe-core";
const maxX = getMaxThumbX(320, DEFAULT_SWIPE_CONFIG.thumbSize, DEFAULT_SWIPE_CONFIG.thumbMargin);
const progress = getProgress(180, maxX);
const isComplete = shouldComplete(progress, DEFAULT_SWIPE_CONFIG.threshold);
console.log({ maxX, progress, isComplete, clamped: clamp(progress, 0, 1) });Main Exports
import {
DEFAULT_SWIPE_CONFIG,
DEFAULT_ANIMATION_CONFIG,
clamp,
createRenderState,
getMaxThumbX,
getProgress,
resolveAnimationConfig,
resolveIsRTL,
shouldComplete,
} from "@freefugga/smooth-swipe-core";Included Types
type SwipeDirection = "auto" | "ltr" | "rtl";
type SwipeResult = "success" | "cancel";
type CompleteBehavior = "reset" | "stay-complete";Notes
- This package does not render a UI component by itself.
- It is a shared foundation used by the React and React Native packages.
- For most app developers, the UI packages are the correct installation target.
License
MIT, copyright Nishidh Jain.
