diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/haptics.ts | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/src/lib/haptics.ts b/src/lib/haptics.ts index b22d69d70..02940f793 100644 --- a/src/lib/haptics.ts +++ b/src/lib/haptics.ts @@ -1,47 +1,20 @@ -import { - impactAsync, - ImpactFeedbackStyle, - notificationAsync, - NotificationFeedbackType, - selectionAsync, -} from 'expo-haptics' +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 class Haptics { - static default() { - if (isWeb) { +export function useHaptics() { + const isHapticsDisabled = useHapticsDisabled() + + return React.useCallback(() => { + if (isHapticsDisabled || isWeb) { return } impactAsync(hapticImpact) - } - static impact(type: ImpactFeedbackStyle = hapticImpact) { - if (isWeb) { - return - } - impactAsync(type) - } - static selection() { - if (isWeb) { - return - } - selectionAsync() - } - static notification = (type: 'success' | 'warning' | 'error') => { - if (isWeb) { - return - } - switch (type) { - case 'success': - return notificationAsync(NotificationFeedbackType.Success) - case 'warning': - return notificationAsync(NotificationFeedbackType.Warning) - case 'error': - return notificationAsync(NotificationFeedbackType.Error) - } - } + }, [isHapticsDisabled]) } |