about summary refs log tree commit diff
path: root/src/lib/haptics.ts
blob: 516940c1cea5bdffc990f3a78cd730b517000d66 (plain) (blame)
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
33
34
35
36
37
38
39
40
import {isIOS, isWeb} from 'platform/detection'
import ReactNativeHapticFeedback, {
  HapticFeedbackTypes,
} from 'react-native-haptic-feedback'

const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s

export class Haptics {
  static default() {
    if (isWeb) {
      return
    }
    ReactNativeHapticFeedback.trigger(hapticImpact)
  }
  static impact(type: HapticFeedbackTypes = hapticImpact) {
    if (isWeb) {
      return
    }
    ReactNativeHapticFeedback.trigger(type)
  }
  static selection() {
    if (isWeb) {
      return
    }
    ReactNativeHapticFeedback.trigger('selection')
  }
  static notification = (type: 'success' | 'warning' | 'error') => {
    if (isWeb) {
      return
    }
    switch (type) {
      case 'success':
        return ReactNativeHapticFeedback.trigger('notificationSuccess')
      case 'warning':
        return ReactNativeHapticFeedback.trigger('notificationWarning')
      case 'error':
        return ReactNativeHapticFeedback.trigger('notificationError')
    }
  }
}