Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'HapticFeedback' lib to TypeScript #26774

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this PR, what about defining a type for the whole file structure?

type HapticFeedback = {
    press: () => void;
    longPress: () => void;
    success: () => void;
    error: () => void;
};

const hapticFeedback: HapticFeedback = {
    press: () => {},
    longPress: () => {},
    success: () => {},
    error: () => {},
};

export default hapticFeedback;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :) @fabioh8010