-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathStreamHapticFeedback.kt
More file actions
29 lines (27 loc) · 1.14 KB
/
StreamHapticFeedback.kt
File metadata and controls
29 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.streamchatreactnative.shared
import android.app.Activity
import android.os.Build
import android.view.HapticFeedbackConstants
object StreamHapticFeedback {
fun trigger(activity: Activity?, type: String) {
val view = activity?.window?.decorView ?: return
val constant = when (type) {
"impactLight" -> HapticFeedbackConstants.KEYBOARD_TAP
"impactMedium" -> HapticFeedbackConstants.VIRTUAL_KEY
"impactHeavy" -> HapticFeedbackConstants.LONG_PRESS
"notificationSuccess" -> if (Build.VERSION.SDK_INT >= 30) {
HapticFeedbackConstants.CONFIRM
} else {
HapticFeedbackConstants.VIRTUAL_KEY
}
"notificationWarning" -> HapticFeedbackConstants.VIRTUAL_KEY
"notificationError" -> if (Build.VERSION.SDK_INT >= 30) {
HapticFeedbackConstants.REJECT
} else {
HapticFeedbackConstants.LONG_PRESS
}
else -> HapticFeedbackConstants.CLOCK_TICK
}
view.performHapticFeedback(constant, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING)
}
}