tooot/src/components/haptics.ts

33 lines
838 B
TypeScript
Raw Normal View History

2020-12-30 14:33:33 +01:00
import * as Haptics from 'expo-haptics'
2021-01-14 00:43:35 +01:00
import { Platform } from 'react-native'
2020-12-30 14:33:33 +01:00
import * as Sentry from 'sentry-expo'
const haptics = (
type: 'Success' | 'Warning' | 'Error' | 'Light' | 'Medium' | 'Heavy'
) => {
2021-01-14 00:43:35 +01:00
if (Platform.OS === 'android') {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle['Light']).catch(error =>
Sentry.Native.captureException(error)
)
return
}
2020-12-30 14:33:33 +01:00
switch (type) {
case 'Success':
case 'Warning':
case 'Error':
Haptics.notificationAsync(Haptics.NotificationFeedbackType[type]).catch(
error => Sentry.Native.captureException(error)
)
break
case 'Light':
case 'Medium':
case 'Heavy':
Haptics.impactAsync(Haptics.ImpactFeedbackStyle[type]).catch(error =>
Sentry.Native.captureException(error)
)
}
}
export default haptics