1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/components/haptics.ts
2021-12-31 15:37:36 +01:00

33 lines
782 B
TypeScript

import * as Haptics from 'expo-haptics'
import { Platform } from 'react-native'
const haptics = (
type: 'Success' | 'Warning' | 'Error' | 'Light' | 'Medium' | 'Heavy'
) => {
if (Platform.OS === 'ios' && parseInt(Platform.Version, 10) <= 12) {
return
}
if (Platform.OS === 'android') {
if (type === 'Error') {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle['Light']).catch(() => {})
}
return
}
switch (type) {
case 'Success':
case 'Warning':
case 'Error':
Haptics.notificationAsync(Haptics.NotificationFeedbackType[type]).catch(
() => {}
)
break
case 'Light':
case 'Medium':
case 'Heavy':
Haptics.impactAsync(Haptics.ImpactFeedbackStyle[type]).catch(() => {})
}
}
export default haptics