EasyCord LogoDocs
Plugin EcosystemHardware & Sensors

Haptics

Trigger native device haptics and vibration feedback.

Haptics Plugin

The EasyCord Haptics plugin provides access to the device's native vibration and haptic feedback motors, allowing you to create rich tactile experiences in your applications.

Installation

npm install @easycord/plugin-haptics

API Reference

vibrate(options?: VibrateOptions)

Triggers a vibration pattern on the device.

Parameters

  • duration (number): Duration of the vibration in milliseconds (Android only).
  • type (HapticsImpactStyle): 'light', 'medium', 'heavy', 'success', 'warning', 'error' (primarily iOS Taptic Engine styles).

Example Usage

import { Haptics, HapticsImpactStyle } from '@easycord/plugin-haptics';

export default function HapticsExample() {
  const triggerSuccess = async () => {
    await Haptics.vibrate({ type: HapticsImpactStyle.Success });
  };

  const triggerHeavy = async () => {
    await Haptics.vibrate({ type: HapticsImpactStyle.Heavy, duration: 500 });
  };

  return (
    <div className="p-4 flex gap-4">
      <button onClick={triggerSuccess} className="bg-green-500 text-white px-4 py-2 rounded">
        Success Haptic
      </button>
      <button onClick={triggerHeavy} className="bg-red-500 text-white px-4 py-2 rounded">
        Heavy Haptic
      </button>
    </div>
  );
}