From 59a0f4968600d437cdaea8f193a634a3c76c5293 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 5 Sep 2023 15:15:07 +0200 Subject: [PATCH] [TS migration] Migrate 'HapticFeedback' lib to TypeScript --- src/libs/HapticFeedback/index.js | 9 --------- .../{index.native.js => index.native.ts} | 17 +++++++++-------- src/libs/HapticFeedback/index.ts | 11 +++++++++++ src/libs/HapticFeedback/types.ts | 6 ++++++ 4 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 src/libs/HapticFeedback/index.js rename src/libs/HapticFeedback/{index.native.js => index.native.ts} (64%) create mode 100644 src/libs/HapticFeedback/index.ts create mode 100644 src/libs/HapticFeedback/types.ts diff --git a/src/libs/HapticFeedback/index.js b/src/libs/HapticFeedback/index.js deleted file mode 100644 index cef9f994ddaf..000000000000 --- a/src/libs/HapticFeedback/index.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Web does not support Haptic feedback - */ -export default { - press: () => {}, - longPress: () => {}, - success: () => {}, - error: () => {}, -}; diff --git a/src/libs/HapticFeedback/index.native.js b/src/libs/HapticFeedback/index.native.ts similarity index 64% rename from src/libs/HapticFeedback/index.native.js rename to src/libs/HapticFeedback/index.native.ts index bc57c74d8d04..f1d7c80aa63d 100644 --- a/src/libs/HapticFeedback/index.native.js +++ b/src/libs/HapticFeedback/index.native.ts @@ -1,28 +1,29 @@ import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; +import {HapticFeedbackError, HapticFeedbackLongPress, HapticFeedbackPress, HapticFeedbackSuccess} from './types'; -function press() { +const press: HapticFeedbackPress = () => { ReactNativeHapticFeedback.trigger('impactLight', { enableVibrateFallback: true, }); -} +}; -function longPress() { +const longPress: HapticFeedbackLongPress = () => { ReactNativeHapticFeedback.trigger('impactHeavy', { enableVibrateFallback: true, }); -} +}; -function success() { +const success: HapticFeedbackSuccess = () => { ReactNativeHapticFeedback.trigger('notificationSuccess', { enableVibrateFallback: true, }); -} +}; -function error() { +const error: HapticFeedbackError = () => { ReactNativeHapticFeedback.trigger('notificationError', { enableVibrateFallback: true, }); -} +}; export default { press, diff --git a/src/libs/HapticFeedback/index.ts b/src/libs/HapticFeedback/index.ts new file mode 100644 index 000000000000..ce4b5ec1917b --- /dev/null +++ b/src/libs/HapticFeedback/index.ts @@ -0,0 +1,11 @@ +import {HapticFeedbackError, HapticFeedbackLongPress, HapticFeedbackPress, HapticFeedbackSuccess} from './types'; + +/** + * Web does not support Haptic feedback + */ +const press: HapticFeedbackPress = () => {}; +const longPress: HapticFeedbackLongPress = () => {}; +const success: HapticFeedbackSuccess = () => {}; +const error: HapticFeedbackError = () => {}; + +export default {press, longPress, success, error}; diff --git a/src/libs/HapticFeedback/types.ts b/src/libs/HapticFeedback/types.ts new file mode 100644 index 000000000000..39d2b36bef21 --- /dev/null +++ b/src/libs/HapticFeedback/types.ts @@ -0,0 +1,6 @@ +type HapticFeedbackPress = () => void; +type HapticFeedbackLongPress = () => void; +type HapticFeedbackSuccess = () => void; +type HapticFeedbackError = () => void; + +export type {HapticFeedbackPress, HapticFeedbackLongPress, HapticFeedbackSuccess, HapticFeedbackError};