react-native-games
Version:
Free games for your react native projects.
1 lines • 1.79 kB
JavaScript
;import * as Haptics from 'expo-haptics';export let HapticType = function(HapticType){HapticType["LIGHT"] = "light";HapticType["MEDIUM"] = "medium";HapticType["HEAVY"] = "heavy";HapticType["SUCCESS"] = "success";HapticType["WARNING"] = "warning";HapticType["ERROR"] = "error";HapticType["SELECTION"] = "selection";return HapticType;}({});let hapticsDisabled = false;export const playHaptic =(type,hapticEnabled = false)=>{if(!hapticEnabled || hapticsDisabled)return;try{switch(type){case HapticType.LIGHT:Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(error =>{console.warn('Light haptic failed:',error);hapticsDisabled = true;});break;case HapticType.MEDIUM:Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium).catch(error =>{console.warn('Medium haptic failed:',error);hapticsDisabled = true;});break;case HapticType.HEAVY:Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy).catch(error =>{console.warn('Heavy haptic failed:',error);hapticsDisabled = true;});break;case HapticType.SUCCESS:Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success).catch(error =>{console.warn('Success haptic failed:',error);hapticsDisabled = true;});break;case HapticType.WARNING:Haptics.notificationAsync(Haptics.NotificationFeedbackType.Warning).catch(error =>{console.warn('Warning haptic failed:',error);hapticsDisabled = true;});break;case HapticType.ERROR:Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error).catch(error =>{console.warn('Error haptic failed:',error);hapticsDisabled = true;});break;case HapticType.SELECTION:Haptics.selectionAsync().catch(error =>{console.warn('Selection haptic failed:',error);hapticsDisabled = true;});break;}}catch(error){console.warn('Haptic feedback failed,disabling haptics:',error);hapticsDisabled = true;}};