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+.
Plain JavaScript Implementation
Step-by-Step Instructions
-
Access the Haptics Module: Ensure that the
haptics
module is available fromwindow.WTN
. -
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.
ES6+ Implementation
Step-by-Step Instructions
-
Import the Trigger Function: Import the
trigger
function from thewebtonative/Haptics
module. -
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.