JindongJindong
Core

Jindong

The main composable for defining and executing haptic patterns

Jindong

The main composable for defining haptic patterns with trigger-based execution.

Signature

@Composable
fun Jindong(
    vararg keys: Any?,
    content: @Composable JindongScope.() -> Unit
)

Parameters

ParameterTypeDescription
keysvararg Any?Keys that trigger re-execution when changed
content@Composable JindongScope.() -> UnitDSL block defining the haptic pattern

Description

Jindong works similarly to LaunchedEffect. When any of the provided keys change, the haptic pattern defined in the content block is compiled and executed.

Key-based Triggering

var count by remember { mutableStateOf(0) }

// Executes when count changes
Jindong(count) {
    Haptic(100.ms)
}

Multiple keys trigger on any change:

// Executes when either key1 OR key2 changes
Jindong(key1, key2) {
    Haptic(100.ms)
}

Immediate Execution on Enter

Use Unit as a key to execute haptic immediately when the composable enters composition:

@Composable
fun WelcomeScreen() {
    // Executes once when screen appears
    Jindong(Unit) {
        Haptic(100.ms, HapticIntensity.MEDIUM)
    }

    Text("Welcome!")
}

This is useful for:

  • Screen entry feedback
  • Initial greeting haptics
  • One-time notifications

Pattern Compilation

The content block is compiled into a HapticPattern containing scheduled events. The pattern is then executed by the HapticExecutor provided via LocalHapticExecutor.

Usage

Basic Usage

@Composable
fun BasicHaptic() {
    var trigger by remember { mutableStateOf(0) }

    Jindong(trigger) {
        Haptic(100.ms)
    }

    Button(onClick = { trigger++ }) {
        Text("Trigger")
    }
}

Complex Pattern

@Composable
fun ComplexHaptic(trigger: Int) {
    Jindong(trigger) {
        Haptic(100.ms, HapticIntensity.MEDIUM)
        Delay(50.ms)
        Repeat(3) {
            Haptic(50.ms, HapticIntensity.STRONG)
            Delay(30.ms)
        }
    }
}

Conditional Content

@Composable
fun ConditionalHaptic(success: Boolean, trigger: Int) {
    Jindong(trigger, success) {
        if (success) {
            Haptic(100.ms, HapticIntensity.MEDIUM)
        } else {
            Repeat(3) {
                Haptic(50.ms, HapticIntensity.HIGH)
                Delay(50.ms)
            }
        }
    }
}

Dynamic Patterns

@Composable
fun DynamicHaptic(intensity: Int, trigger: Int) {
    Jindong(trigger, intensity) {
        RepeatWithIndex(intensity) { index ->
            val fade = HapticIntensity.Custom(1.0f - (index * 0.1f))
            Haptic(50.ms, fade)
            Delay(30.ms)
        }
    }
}

Requirements

Jindong must be used within a JindongProvider:

JindongProvider {
    Jindong(trigger) {
        // ...
    }
}

Without a provider, LocalHapticExecutor.current will throw an error.

Available DSL Functions

Within the JindongScope, you can use:

FunctionDescription
HapticEmit a vibration
DelayPause the pattern
SequenceGroup events sequentially
RepeatRepeat content N times
RepeatWithIndexRepeat with index access

Notes

  • Keys work identically to LaunchedEffect keys
  • The pattern executes asynchronously
  • Content block is compiled once per key change
  • Platform-specific execution handled automatically

See Also