about summary refs log tree commit diff
path: root/src/lib/haptics.ts
blob: 02940f793d09ec367616a2e22f25ef5c720baabf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React from 'react'
import {impactAsync, ImpactFeedbackStyle} from 'expo-haptics'

import {isIOS, isWeb} from 'platform/detection'
import {useHapticsDisabled} from 'state/preferences/disable-haptics'

const hapticImpact: ImpactFeedbackStyle = isIOS
  ? ImpactFeedbackStyle.Medium
  : ImpactFeedbackStyle.Light // Users said the medium impact was too strong on Android; see APP-537s

export function useHaptics() {
  const isHapticsDisabled = useHapticsDisabled()

  return React.useCallback(() => {
    if (isHapticsDisabled || isWeb) {
      return
    }
    impactAsync(hapticImpact)
  }, [isHapticsDisabled])
}