forked from plaa/react-native-haptic-feedback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 944 Bytes
/
index.js
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
30
31
32
import { NativeModules } from 'react-native';
const defaultOptions = {
enableVibrateFallback: false,
ignoreAndroidSystemSettings: false,
}
class RNReactNativeHapticFeedback {
static trigger = (type = 'selection', options = {}) => {
const triggerOptions = createTriggerOptions(options)
try {
NativeModules.RNReactNativeHapticFeedback.trigger(type, triggerOptions);
} catch (err) {
console.warn('RNReactNativeHapticFeedback is not available');
}
}
}
const createTriggerOptions = options => {
// if options is a boolean we're using an api <=1.6 and we should pass use it to set the enableVibrateFallback option
if (typeof options === 'boolean') {
return {
...defaultOptions,
enableVibrateFallback: options
}
} else {
return { ...defaultOptions, ...options }
}
}
export default RNReactNativeHapticFeedback;