HapticFeedback
Implements Telegram Mini Apps haptic feedback functionality.
Initialization
Component constructor accepts Telegram Mini Apps version and optional function to call Telegram Mini Apps methods.
import { HapticFeedback, postEvent } from '@tma.js/sdk';
const haptic = new HapticFeedback('6.3', postEvent);
import { HapticFeedback, postEvent } from '@tma.js/sdk';
const haptic = new HapticFeedback('6.3', postEvent);
Notifications
HapticFeedback
supports 3 types of haptic events - impactOccurred
, notificationOccurred
and selectionChanged
.
impactOccurred
A method tells that an impact occurred. The Telegram app may play the appropriate haptics based on style value passed. Style of impact occurred haptic event:
light
, indicates a collision between small or lightweight UI objectsmedium
, indicates a collision between medium-sized or medium-weight UI objectsheavy
, indicates a collision between large or heavyweight UI objectsrigid
, indicates a collision between hard or inflexible UI objectssoft
, indicates a collision between soft or flexible UI objects
haptic.impactOccurred('medium');
haptic.impactOccurred('medium');
notificationOccurred
A method tells that a task or action has succeeded, failed, or produced a warning. The Telegram app may play the appropriate haptics based on type value passed. Type of notification occurred type event.
error
, indicates that a task or action has failed,success
, indicates that a task or action has completed successfully,warning
, indicates that a task or action produced a warning.
haptic.notificationOccurred('success');
haptic.notificationOccurred('success');
selectionChanged
A method tells that the user has changed a selection.
haptic.selectionChanged();
haptic.selectionChanged();
Methods support
List of methods, which could be used in supports
component instance method:
notificationOccurred
impactOccurred
selectionChanged
import { HapticFeedback } from '@tma.js/sdk';
const hapticFeedback = new HapticFeedback(...);
hapticFeedback.supports('notificationOccurred');
hapticFeedback.supports('impactOccurred');
hapticFeedback.supports('selectionChanged');
import { HapticFeedback } from '@tma.js/sdk';
const hapticFeedback = new HapticFeedback(...);
hapticFeedback.supports('notificationOccurred');
hapticFeedback.supports('impactOccurred');
hapticFeedback.supports('selectionChanged');