Skip to content

Commit

Permalink
[TS migration] Migrate 'HapticFeedback' lib to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek committed Sep 5, 2023
1 parent ec95ab0 commit 59a0f49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
9 changes: 0 additions & 9 deletions src/libs/HapticFeedback/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/libs/HapticFeedback/index.ts
Original file line number Diff line number Diff line change
@@ -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};
6 changes: 6 additions & 0 deletions src/libs/HapticFeedback/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type HapticFeedbackPress = () => void;
type HapticFeedbackLongPress = () => void;
type HapticFeedbackSuccess = () => void;
type HapticFeedbackError = () => void;

export type {HapticFeedbackPress, HapticFeedbackLongPress, HapticFeedbackSuccess, HapticFeedbackError};

0 comments on commit 59a0f49

Please sign in to comment.