
Utility library enabling device vibration control with customizable timing and patterns, featuring easy integration and platform-specific initialization through a common interface.
Kotlin Multiplatform utility library for vibrate📱!
In lib.versions.toml include this dependency version catalog
[versions]
vibrate = "1.1.0"
[libraries]
vibrate = { module = "io.github.jmseb3:vibrate", version.ref = "vibrate" }commonMain.dependencies {
implementation(libs.vibrate)
}or In build.gradle of app module, include this dependency
commonMain.dependencies {
implementation("io.github.jmseb3:vibrate:1.1.0")
}Example app source lives in sample/.
./gradlew :sample:webApp:jsBrowserDevelopmentRun --continue
./gradlew :sample:webApp:wasmJsBrowserDevelopmentRun --continue
sample:androidApp from Android Studiosample/iosApp/iosApp.xcodeproj in Xcode and runAll durations are in milliseconds.
if (VibratorManager.isSupported()) {
VibratorManager.vibrate(300)
}VibratorManager.vibrate(3000)3000 means 3 seconds.
VibratorManager.vibrate(3000, strength = 0.5f)
VibratorManager.vibrate(
VibrationPreset.Success,
strength = 0.8f
)strength uses a normalized 0f..1f range.
VibratorManager.vibratePattern(listOf(300, 500, 700, 500))[300, 500, 700, 500] means:
300ms
500ms
700ms
500ms
You can also use typed patterns:
VibratorManager.vibratePattern(
listOf(
VibratePattern(delay = 0, vibrate = 80),
VibratePattern(delay = 60, vibrate = 120)
)
)Built-in presets are available through VibrationPreset.
VibratorManager.vibrate(VibrationPreset.Success)
VibratorManager.vibrate(VibrationPreset.Error)Available presets:
VibrationPreset.SuccessVibrationPreset.ClickVibrationPreset.DoubleClickVibrationPreset.TickVibrationPreset.WarningVibrationPreset.ErrorVibrationPreset.HeartbeatVibrationPreset.SosIf you want to inspect or customize a preset, you can also read its pattern list:
val successPattern = VibrationPreset.Success.patterns
val successDuration = VibrationPreset.Success.durationMillisVibratorManager.stopVibrate()This feature is supported by the Vibrate API.
For more detailed information, please refer to the official documentation:
Kotlin Multiplatform utility library for vibrate📱!
In lib.versions.toml include this dependency version catalog
[versions]
vibrate = "1.1.0"
[libraries]
vibrate = { module = "io.github.jmseb3:vibrate", version.ref = "vibrate" }commonMain.dependencies {
implementation(libs.vibrate)
}or In build.gradle of app module, include this dependency
commonMain.dependencies {
implementation("io.github.jmseb3:vibrate:1.1.0")
}Example app source lives in sample/.
./gradlew :sample:webApp:jsBrowserDevelopmentRun --continue
./gradlew :sample:webApp:wasmJsBrowserDevelopmentRun --continue
sample:androidApp from Android Studiosample/iosApp/iosApp.xcodeproj in Xcode and runAll durations are in milliseconds.
if (VibratorManager.isSupported()) {
VibratorManager.vibrate(300)
}VibratorManager.vibrate(3000)3000 means 3 seconds.
VibratorManager.vibrate(3000, strength = 0.5f)
VibratorManager.vibrate(
VibrationPreset.Success,
strength = 0.8f
)strength uses a normalized 0f..1f range.
VibratorManager.vibratePattern(listOf(300, 500, 700, 500))[300, 500, 700, 500] means:
300ms
500ms
700ms
500ms
You can also use typed patterns:
VibratorManager.vibratePattern(
listOf(
VibratePattern(delay = 0, vibrate = 80),
VibratePattern(delay = 60, vibrate = 120)
)
)Built-in presets are available through VibrationPreset.
VibratorManager.vibrate(VibrationPreset.Success)
VibratorManager.vibrate(VibrationPreset.Error)Available presets:
VibrationPreset.SuccessVibrationPreset.ClickVibrationPreset.DoubleClickVibrationPreset.TickVibrationPreset.WarningVibrationPreset.ErrorVibrationPreset.HeartbeatVibrationPreset.SosIf you want to inspect or customize a preset, you can also read its pattern list:
val successPattern = VibrationPreset.Success.patterns
val successDuration = VibrationPreset.Success.durationMillisVibratorManager.stopVibrate()This feature is supported by the Vibrate API.
For more detailed information, please refer to the official documentation: