Core API
Using Jindong without Compose Runtime
Core API
Module: jindong-core | Package: io.github.compose.jindong.core
The Core API allows you to use Jindong haptic patterns without Compose Runtime dependency. This is useful for:
- Non-Compose Kotlin Multiplatform projects
- ViewModel or Repository layer haptic triggers
- Background services or workers
Installation
Building Patterns
Use buildHapticPattern to create haptic patterns:
Transients, continuous feedback, and curves
The common DSL supports fixed intensity and sharpness, plus linear intensity and sharpness curves:
This pattern contains impacts at 0ms, 80ms, and 160ms, followed by continuous feedback from 240ms through 540ms. Transients do not advance the logical timeline. Their physical pulse length depends on the backend. Continuous feedback requires a positive duration. Sharpness is normalized texture intent, not frequency in Hz.
A curve replaces its corresponding fixed value. Control points use event-relative time and absolute values in 0..1.
Values and sharpness must be finite. Curves require at least two points, starting at 0ms and ending at the event duration.
Rounded point times must strictly increase. A pattern permits at most 10,000 events and 100,000 control points.
Curves and events are immutable values. include, repetition, then, and Clip preserve their properties.
scaleIntensity scales and clamps intensity curves. timeStretch scales their absolute times and rejects rounded duplicate points.
reversed also reverses curves within their events.
Pattern Duration
HapticPattern.durationMs includes trailing silence. Builders pass the complete duration, and include and transforms preserve it.
A delay-only pattern has no events and can have a positive duration.
Equality includes events and duration. Events-only construction uses the latest event end as its default duration.
Pass HapticPattern(events, durationMs = ...) when you construct a timeline with trailing silence.
Duration inputs must be finite and non-negative. They round to the nearest millisecond, with half-milliseconds rounded up.
The shared Duration.toHapticMilliseconds() conversion applies that rule. Vibrations require at least 1ms; zero delays are allowed.
See Migrating to 2.0 for source and ABI changes.
Executing Patterns
Suspend Function (Recommended)
Use play() to execute and wait for completion:
Fire-and-Forget
Use playAsync() when you don't need to wait:
Inline Execution
Use playHaptic for one-off patterns:
HapticManager
HapticManager is a singleton that manages haptic execution:
Platform Initialization
Android
Automatic initialization via JindongInitializer ContentProvider. No manual setup needed.
For multi-process apps, call manually:
iOS
No initialization required.
DSL Reference
haptic
Creates a vibration event:
transient and continuous
Build reusable curves with hapticCurve { point(time: Duration, value: Float) } from io.github.compose.jindong.core.dsl.
HapticCurve and HapticControlPoint are also available in io.github.compose.jindong.core.model for direct construction.
delay
Adds a pause between events:
repeat
Repeats a block N times:
repeatWithIndex
Repeats with index access for dynamic patterns:
sequence
Groups elements (optional, for organization):
include
Includes an existing pattern:
If included patterns overlap in time, they are not summed. A single vibration motor plays one amplitude at a time, so at each instant the strongest active event wins:
Examples
ViewModel Usage
Repository Pattern
Comparison with Compose API
| Feature | Core API | Compose API |
|---|---|---|
| Compose Runtime | Not required | Required |
| Trigger mechanism | Manual (play()) | Key-based (like LaunchedEffect) |
| Pattern definition | buildHapticPattern {} | Jindong {} composable |
| DSL style | Regular functions | @Composable functions |
| Use case | ViewModels, services | UI components |
See Also
- Getting Started - Installation guide
- HapticIntensity - Intensity levels
- Compose API - Compose-based API