about summary refs log tree commit diff
path: root/src/lib/haptics.ts
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-04-11 15:20:26 -0700
committerGitHub <noreply@github.com>2024-04-11 15:20:26 -0700
commit740cd029d7162a936d16b427201eb8972e365b94 (patch)
treeff4cf80cc8cd88bd958abd68c3cb3aa46328240e /src/lib/haptics.ts
parent9007810cdb5ffc8fbdf8e2a2af6c073b76b318f3 (diff)
downloadvoidsky-740cd029d7162a936d16b427201eb8972e365b94.tar.zst
Improve Android haptic, offer toggle for haptics in the app (#3482)
* improve android haptics, offer toggle for haptics

* update haptics.ts

* default to false

* simplify to `playHaptic`

* just leave them as `feedInfo`

* use a hook for `playHaptic`

* missed one of them
Diffstat (limited to 'src/lib/haptics.ts')
-rw-r--r--src/lib/haptics.ts45
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])
 }