From b34119cf5b4326850c5eb2007625115bb0ceac77 Mon Sep 17 00:00:00 2001 From: Robert Kozik Date: Thu, 6 Apr 2023 17:53:54 +0200 Subject: [PATCH 1/3] merge haptic native implementations into one, implement success, error, press, long press fhpatic functions --- src/libs/HapticFeedback/index.android.js | 18 ------------- src/libs/HapticFeedback/index.ios.js | 12 --------- src/libs/HapticFeedback/index.js | 5 +++- src/libs/HapticFeedback/index.native.js | 33 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 31 deletions(-) delete mode 100644 src/libs/HapticFeedback/index.android.js delete mode 100644 src/libs/HapticFeedback/index.ios.js create mode 100644 src/libs/HapticFeedback/index.native.js 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, +}; From c977f4cccee2dda4d1017b45f6a4823698182c96 Mon Sep 17 00:00:00 2001 From: Robert Kozik Date: Thu, 6 Apr 2023 17:54:31 +0200 Subject: [PATCH 2/3] change removed haptic trigger function to longPress --- .../PressableWithSecondaryInteraction/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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} From ff0b335fd068ca1aec88c7750ea02559b32c8c8c Mon Sep 17 00:00:00 2001 From: Robert Kozik Date: Thu, 6 Apr 2023 17:54:42 +0200 Subject: [PATCH 3/3] change removed haptic trigger function to longPress/press --- src/components/Button.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); }}