What is expo-haptics?
The expo-haptics package provides a way to trigger haptic feedback on iOS and Android devices. This can be used to enhance user experience by providing tactile feedback in response to user interactions.
What are expo-haptics's main functionalities?
Impact Feedback
This feature allows you to trigger an impact feedback, which is a physical tap or bump. The `impactAsync` function can take different styles such as Light, Medium, and Heavy.
import * as Haptics from 'expo-haptics';
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
Notification Feedback
This feature allows you to trigger notification feedback, which is a series of taps that indicate a notification. The `notificationAsync` function can take different types such as Success, Warning, and Error.
import * as Haptics from 'expo-haptics';
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
Selection Feedback
This feature allows you to trigger selection feedback, which is a light tap used to indicate a selection change. The `selectionAsync` function does not take any parameters.
import * as Haptics from 'expo-haptics';
Haptics.selectionAsync();
Other packages similar to expo-haptics
react-native-haptic-feedback
The react-native-haptic-feedback package provides similar functionalities for triggering haptic feedback on iOS and Android devices. It offers more customization options for feedback patterns and intensities compared to expo-haptics.
react-native-vibration
The react-native-vibration package allows you to trigger vibration patterns on Android and iOS devices. While it does not offer the same level of haptic feedback customization as expo-haptics, it is useful for simpler vibration needs.
expo-haptics
Provides access to the system's haptics engine on iOS and vibration effects on Android.
API documentation
Installation
This package is pre-installed in managed Expo projects. You may skip the rest of the installation guide if this applies to you.
For bare React Native projects, you must ensure that you have installed and configured the react-native-unimodules
package before continuing.
Add the package to your npm dependencies
npm install expo-haptics
Configure for iOS
Run pod install
in the ios directory after installing the npm package.
Configure for Android
No additional set up necessary.
Contributing
Contributions are very welcome! Please refer to guidelines described in the contributing guide.