Haptic Feedback

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

  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 impact
  • impactMedium: Medium impact
  • impactHeavy: Heavy impact
  • notificationSuccess: Success notification
  • notificationWarning: Warning notification
  • notificationError: 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

  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 impact
  • impactMedium: Medium impact
  • impactHeavy: Heavy impact
  • notificationSuccess: Success notification
  • notificationWarning: Warning notification
  • notificationError: 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.


media-icon
media-icon
media-icon
media-icon

â“’2024 Orufy Technologies All Rights Reserved.