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
|
|
|
|
|
|
|
const haptics = (
|
|
|
|
type: 'Success' | 'Warning' | 'Error' | 'Light' | 'Medium' | 'Heavy'
|
|
|
|
) => {
|
2021-12-31 15:37:36 +01:00
|
|
|
if (Platform.OS === 'ios' && parseInt(Platform.Version, 10) <= 12) {
|
|
|
|
return
|
|
|
|
}
|
2021-01-14 00:43:35 +01:00
|
|
|
if (Platform.OS === 'android') {
|
2021-03-11 22:31:00 +01:00
|
|
|
if (type === 'Error') {
|
|
|
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle['Light']).catch(() => {})
|
|
|
|
}
|
2021-01-14 00:43:35 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-30 14:33:33 +01:00
|
|
|
switch (type) {
|
|
|
|
case 'Success':
|
|
|
|
case 'Warning':
|
|
|
|
case 'Error':
|
|
|
|
Haptics.notificationAsync(Haptics.NotificationFeedbackType[type]).catch(
|
2021-03-11 22:31:00 +01:00
|
|
|
() => {}
|
2020-12-30 14:33:33 +01:00
|
|
|
)
|
|
|
|
break
|
|
|
|
case 'Light':
|
|
|
|
case 'Medium':
|
|
|
|
case 'Heavy':
|
2021-03-11 22:31:00 +01:00
|
|
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle[type]).catch(() => {})
|
2020-12-30 14:33:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default haptics
|