Vibration

Vibration is the phone's motor, not the Taptic Engine - use this for an alarm, a timer or an incoming call, not for button feedback (that is haptics, in @ng-native/expo).

Import
import { Vibration } from '@ng-native/device';
Inject
inject(Vibration)
import { Component, inject } from '@angular/core';
import { Vibration } from '@ng-native/device';

@Component({ selector: 'app-timer', template: `<view />` })
export class Timer {
  private readonly vibration = inject(Vibration);

  protected onTimerDone(): void {
    this.vibration.pattern([0, 500, 200, 500], { repeat: true });
  }

  protected dismiss(): void {
    this.vibration.stop();
  }
}

buzz(durationMs?) is a single buzz, 400ms by default. pattern(millis, options?) is a pattern of waits and buzzes in milliseconds, starting with a wait; repeat: true runs it until stop(), which is for something that must be answered - an alarm, a call - and is a promise to call stop() rather than a decoration. stop() cancels whatever is running.

iOS has one duration and ignores the number, so a pattern there is on and off at a fixed strength; Android takes the milliseconds as written. Both are said plainly rather than papered over, because a pattern designed on Android does not feel the same on iOS and nothing here can make it.

Off a device

Off a device every method does nothing, because there is no Vibration module underneath it.

Reference

Vibrationservice@ng-native/device
import { Vibration } from '@ng-native/device';

Methods

buzz(durationMs = 400): void

A single buzz. The duration is Android's; iOS vibrates for its own fixed length.

pattern(millis: readonly number[], options: { repeat?: boolean } = {}): void

A pattern of waits and buzzes, in milliseconds, starting with a wait.

Angular components as native iOS and Android views, built and shipped with Expo.

An alpha. MIT licensed. Sponsor its development.

An independent project, not affiliated with or endorsed by Google, the Angular team or Expo. Angular is a trademark of Google LLC.