HAPTIC Feedback
HAPTIC Feedback can enhance the user experience by engaging the sense of touch and providing meaningful tactile responses in your app or game. This guide will walk you through the steps to trigger haptic feedback using predefined vibration patterns with plain JavaScript and ES6+.
Step-by-Step Implementation of Plain JavaScript
1. Access the Haptics Module: Ensure that the haptics
module is available from window.WTN
.
2. Trigger Haptic Feedback: Use the haptics.trigger
method to initiate haptic feedback with the desired effect.
Here's an example code snippet:
const { haptics } = window.WTN;
haptics.trigger({
effect: 'impactMedium'
});
Available Haptic Effects
impactLight
: Light impactimpactMedium
: Medium impactimpactHeavy
: Heavy impactnotificationSuccess
: Success notificationnotificationWarning
: Warning notificationnotificationError
: Error notification
Default Effect
If you don't provide an effect or provide an incorrect value, a default haptic effect will be triggered.
Step-by-Step Implementation of ES6+
1. Import the Trigger Function: Import the trigger
function from the webtonative/Haptics
module.
2. Trigger Haptic Feedback: Use the trigger
method to initiate haptic feedback with the desired effect.
Here's an example code snippet:
import { trigger } from "webtonative/Haptics";
trigger({
effect: 'impactMedium'
});
Available Haptic Effects
impactLight
: Light impactimpactMedium
: Medium impactimpactHeavy
: Heavy impactnotificationSuccess
: Success notificationnotificationWarning
: Warning notificationnotificationError
: Error notification
Default Effect
If you don't provide an effect or provide an incorrect value, a default haptic effect will be triggered.
Summary
By following these steps, you can easily implement haptic feedback in your app or game, enhancing user interaction through tactile responses. Choose from various predefined effects to convey different types of feedback. If you encounter any issues, refer to the documentation or support resources for additional assistance.