diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-05-25 21:17:11 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2023-05-25 21:17:11 -0500 |
commit | 7b6948e6171b448e271f0564efd1f186ccadb9b8 (patch) | |
tree | e0d1b6e9f9c863cbff53f8832fd55d03cb670a83 /src/lib/haptics.ts | |
parent | 15c1b6ee157471807a723161066ba4ce5e12c0b5 (diff) | |
parent | e832352e9844002408b45291396a3c495be23276 (diff) | |
download | voidsky-7b6948e6171b448e271f0564efd1f186ccadb9b8.tar.zst |
Merge branch 'custom-algos' into main
Diffstat (limited to 'src/lib/haptics.ts')
-rw-r--r-- | src/lib/haptics.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib/haptics.ts b/src/lib/haptics.ts new file mode 100644 index 000000000..516940c1c --- /dev/null +++ b/src/lib/haptics.ts @@ -0,0 +1,40 @@ +import {isIOS, isWeb} from 'platform/detection' +import ReactNativeHapticFeedback, { + HapticFeedbackTypes, +} from 'react-native-haptic-feedback' + +const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s + +export class Haptics { + static default() { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger(hapticImpact) + } + static impact(type: HapticFeedbackTypes = hapticImpact) { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger(type) + } + static selection() { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger('selection') + } + static notification = (type: 'success' | 'warning' | 'error') => { + if (isWeb) { + return + } + switch (type) { + case 'success': + return ReactNativeHapticFeedback.trigger('notificationSuccess') + case 'warning': + return ReactNativeHapticFeedback.trigger('notificationWarning') + case 'error': + return ReactNativeHapticFeedback.trigger('notificationError') + } + } +} |