Skip to content

Commit

Permalink
Merge types into a single one
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek committed Sep 11, 2023
1 parent 59a0f49 commit 4df3b60
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
52 changes: 23 additions & 29 deletions src/libs/HapticFeedback/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import {HapticFeedbackError, HapticFeedbackLongPress, HapticFeedbackPress, HapticFeedbackSuccess} from './types';
import HapticFeedback from './types';

const press: HapticFeedbackPress = () => {
ReactNativeHapticFeedback.trigger('impactLight', {
enableVibrateFallback: true,
});
const hapticFeedback: HapticFeedback = {
press: () => {
ReactNativeHapticFeedback.trigger('impactLight', {
enableVibrateFallback: true,
});
},
longPress: () => {
ReactNativeHapticFeedback.trigger('impactHeavy', {
enableVibrateFallback: true,
});
},
success: () => {
ReactNativeHapticFeedback.trigger('notificationSuccess', {
enableVibrateFallback: true,
});
},
error: () => {
ReactNativeHapticFeedback.trigger('notificationError', {
enableVibrateFallback: true,
});
},
};

const longPress: HapticFeedbackLongPress = () => {
ReactNativeHapticFeedback.trigger('impactHeavy', {
enableVibrateFallback: true,
});
};

const success: HapticFeedbackSuccess = () => {
ReactNativeHapticFeedback.trigger('notificationSuccess', {
enableVibrateFallback: true,
});
};

const error: HapticFeedbackError = () => {
ReactNativeHapticFeedback.trigger('notificationError', {
enableVibrateFallback: true,
});
};

export default {
press,
longPress,
success,
error,
};
export default hapticFeedback;
14 changes: 8 additions & 6 deletions src/libs/HapticFeedback/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {HapticFeedbackError, HapticFeedbackLongPress, HapticFeedbackPress, HapticFeedbackSuccess} from './types';
import HapticFeedback from './types';

/**
* Web does not support Haptic feedback
*/
const press: HapticFeedbackPress = () => {};
const longPress: HapticFeedbackLongPress = () => {};
const success: HapticFeedbackSuccess = () => {};
const error: HapticFeedbackError = () => {};
const hapticFeedback: HapticFeedback = {
press: () => {},
longPress: () => {},
success: () => {},
error: () => {},
};

export default {press, longPress, success, error};
export default hapticFeedback;
12 changes: 7 additions & 5 deletions src/libs/HapticFeedback/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type HapticFeedbackPress = () => void;
type HapticFeedbackLongPress = () => void;
type HapticFeedbackSuccess = () => void;
type HapticFeedbackError = () => void;
type HapticFeedback = {
press: () => void;
longPress: () => void;
success: () => void;
error: () => void;
};

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

0 comments on commit 4df3b60

Please sign in to comment.