mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import * as Device from 'expo-device'
3import {impactAsync, ImpactFeedbackStyle} from 'expo-haptics'
4
5import {isIOS, isWeb} from '#/platform/detection'
6import {useHapticsDisabled} from '#/state/preferences/disable-haptics'
7import * as Toast from '#/view/com/util/Toast'
8
9export function useHaptics() {
10 const isHapticsDisabled = useHapticsDisabled()
11
12 return React.useCallback(
13 (strength: 'Light' | 'Medium' | 'Heavy' = 'Medium') => {
14 if (isHapticsDisabled || isWeb) {
15 return
16 }
17
18 // Users said the medium impact was too strong on Android; see APP-537s
19 const style = isIOS
20 ? ImpactFeedbackStyle[strength]
21 : ImpactFeedbackStyle.Light
22 impactAsync(style)
23
24 // DEV ONLY - show a toast when a haptic is meant to fire on simulator
25 if (__DEV__ && !Device.isDevice) {
26 Toast.show(`Buzzz!`)
27 }
28 },
29 [isHapticsDisabled],
30 )
31}