Files
bsky-social-app/src/lib/haptics.ts
T
Eric Bailey 0589bd7d9e Move /platform/detection vars into /env (#9707)
* Add platform vars to env

* Replace /platform/detection with /env
2026-01-16 16:28:17 -06:00

32 lines
916 B
TypeScript

import React from 'react'
import * as Device from 'expo-device'
import {impactAsync, ImpactFeedbackStyle} from 'expo-haptics'
import {useHapticsDisabled} from '#/state/preferences/disable-haptics'
import {IS_IOS, IS_WEB} from '#/env'
export function useHaptics() {
const isHapticsDisabled = useHapticsDisabled()
return React.useCallback(
(strength: 'Light' | 'Medium' | 'Heavy' = 'Medium') => {
if (isHapticsDisabled || IS_WEB) {
return
}
// Users said the medium impact was too strong on Android; see APP-537s
const style = IS_IOS
? ImpactFeedbackStyle[strength]
: ImpactFeedbackStyle.Light
impactAsync(style)
// DEV ONLY - show a toast when a haptic is meant to fire on simulator
if (__DEV__ && !Device.isDevice) {
// disabled because it's annoying
// Toast.show(`Buzzz!`)
}
},
[isHapticsDisabled],
)
}