Core
JindongScope
DSL scope interface for defining haptic patterns
JindongScope
The scope interface that provides the DSL for defining haptic patterns.
Definition
@JindongScopeMarker
interface JindongScopeDescription
JindongScope is the receiver for the Jindong content block. It serves two purposes:
- DSL Extension Point: All haptic DSL functions are defined as extensions on
JindongScope - Scope Control: The
@JindongScopeMarkerannotation prevents implicit nesting
Available Functions
Functions available within JindongScope:
| Function | Description |
|---|---|
Haptic | Emit a vibration event |
Delay | Pause the pattern |
Sequence | Group events sequentially |
Repeat | Repeat content N times |
RepeatWithIndex | Repeat with index access |
Usage
The scope is automatically provided by Jindong:
Jindong(trigger) {
// Inside JindongScope
Haptic(100.ms)
Delay(50.ms)
Haptic(50.ms)
}DSL Functions as Extensions
All haptic functions are extensions on JindongScope:
@Composable
fun JindongScope.Haptic(
duration: Duration,
intensity: HapticIntensity = HapticIntensity.MEDIUM
)
@Composable
fun JindongScope.Delay(duration: Duration)
@Composable
fun JindongScope.Repeat(
count: Int,
content: @Composable JindongScope.() -> Unit
)Scope Marker
The @JindongScopeMarker annotation prevents confusing nested scopes:
@DslMarker
annotation class JindongScopeMarkerThis means you cannot accidentally access outer scopes:
Jindong(trigger) {
Repeat(3) {
// Still in JindongScope - works fine
Haptic(50.ms)
}
}Composable Support
The scope supports standard Compose patterns:
Conditionals
Jindong(trigger) {
if (isSuccess) {
Haptic(100.ms, HapticIntensity.MEDIUM)
} else {
Haptic(50.ms, HapticIntensity.HIGH)
}
}When Expressions
Jindong(trigger) {
when (state) {
State.SUCCESS -> Haptic(100.ms, HapticIntensity.LIGHT)
State.ERROR -> Repeat(3) { Haptic(50.ms); Delay(50.ms) }
State.WARNING -> Haptic(150.ms, HapticIntensity.MEDIUM)
}
}Loops
Jindong(trigger) {
// Using RepeatWithIndex for index access
RepeatWithIndex(5) { index ->
val intensity = HapticIntensity.Custom(1.0f - index * 0.2f)
Haptic(50.ms, intensity)
Delay(30.ms)
}
}Internal Implementation
The default implementation is straightforward:
internal class JindongScopeImpl : JindongScopeThe actual behavior comes from the DSL extension functions, not the scope interface itself.