diff --git a/src/components/Button.js b/src/components/Button.js index 5a8236e675d0..329153d1993b 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -241,13 +241,13 @@ class Button extends Component { } if (this.props.shouldEnableHapticFeedback) { - HapticFeedback.trigger(); + HapticFeedback.press(); } this.props.onPress(e); }} onLongPress={(e) => { if (this.props.shouldEnableHapticFeedback) { - HapticFeedback.trigger(); + HapticFeedback.longPress(); } this.props.onLongPress(e); }} diff --git a/src/components/PressableWithSecondaryInteraction/index.native.js b/src/components/PressableWithSecondaryInteraction/index.native.js index f186146b4134..c51671ba835c 100644 --- a/src/components/PressableWithSecondaryInteraction/index.native.js +++ b/src/components/PressableWithSecondaryInteraction/index.native.js @@ -20,7 +20,7 @@ const PressableWithSecondaryInteraction = (props) => { onPress={props.onPress} onLongPress={(e) => { e.preventDefault(); - HapticFeedback.trigger(); + HapticFeedback.longPress(); props.onSecondaryInteraction(e); }} onPressIn={props.onPressIn} diff --git a/src/libs/HapticFeedback/index.android.js b/src/libs/HapticFeedback/index.android.js deleted file mode 100644 index e0e077a3513b..000000000000 --- a/src/libs/HapticFeedback/index.android.js +++ /dev/null @@ -1,18 +0,0 @@ -import {Platform} from 'react-native'; -import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; - -function trigger() { - // The constant effectHeavyClick is added in API level 29. - // Docs: https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_HEAVY_CLICK - // We use keyboardTap added in API level 8 as a fallback. - // Docs: https://developer.android.com/reference/android/view/HapticFeedbackConstants#KEYBOARD_TAP - if (Platform.Version >= 29) { - ReactNativeHapticFeedback.trigger('effectHeavyClick'); - return; - } - ReactNativeHapticFeedback.trigger('keyboardTap'); -} - -export default { - trigger, -}; diff --git a/src/libs/HapticFeedback/index.ios.js b/src/libs/HapticFeedback/index.ios.js deleted file mode 100644 index d9b002621eb7..000000000000 --- a/src/libs/HapticFeedback/index.ios.js +++ /dev/null @@ -1,12 +0,0 @@ - -import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; - -function trigger() { - ReactNativeHapticFeedback.trigger('selection', { - enableVibrateFallback: true, - }); -} - -export default { - trigger, -}; diff --git a/src/libs/HapticFeedback/index.js b/src/libs/HapticFeedback/index.js index 39dbfb3c17aa..cef9f994ddaf 100644 --- a/src/libs/HapticFeedback/index.js +++ b/src/libs/HapticFeedback/index.js @@ -2,5 +2,8 @@ * Web does not support Haptic feedback */ export default { - trigger: () => {}, + press: () => {}, + longPress: () => {}, + success: () => {}, + error: () => {}, }; diff --git a/src/libs/HapticFeedback/index.native.js b/src/libs/HapticFeedback/index.native.js new file mode 100644 index 000000000000..769eacbb1a5c --- /dev/null +++ b/src/libs/HapticFeedback/index.native.js @@ -0,0 +1,33 @@ + +import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; + +function press() { + ReactNativeHapticFeedback.trigger('impactLight', { + enableVibrateFallback: true, + }); +} + +function longPress() { + ReactNativeHapticFeedback.trigger('impactHeavy', { + enableVibrateFallback: true, + }); +} + +function success() { + ReactNativeHapticFeedback.trigger('notificationSuccess', { + enableVibrateFallback: true, + }); +} + +function error() { + ReactNativeHapticFeedback.trigger('notificationError', { + enableVibrateFallback: true, + }); +} + +export default { + press, + longPress, + success, + error, +};