BlueWallet/blue_modules/hapticFeedback.ts
2024-05-21 11:56:10 +01:00

26 lines
907 B
TypeScript

import DeviceInfo, { PowerState } from 'react-native-device-info';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
// Define a const enum for HapticFeedbackTypes
export const enum HapticFeedbackTypes {
ImpactLight = 'impactLight',
ImpactMedium = 'impactMedium',
ImpactHeavy = 'impactHeavy',
Selection = 'selection',
NotificationSuccess = 'notificationSuccess',
NotificationWarning = 'notificationWarning',
NotificationError = 'notificationError',
}
const triggerHapticFeedback = (type: HapticFeedbackTypes) => {
DeviceInfo.getPowerState().then((state: Partial<PowerState>) => {
if (!state.lowPowerMode) {
ReactNativeHapticFeedback.trigger(type, { ignoreAndroidSystemSettings: false, enableVibrateFallback: true });
} else {
console.log('Haptic feedback not triggered due to low power mode.');
}
});
};
export default triggerHapticFeedback;