Code Reference

Vibration

React Native · Reference cheat sheet

Vibration

React Native · Reference cheat sheet


📋 Overview

Vibration triggers the device vibrator for tactile feedback. Simple on Android/iOS; patterns are mainly Android. For richer feedback on iOS, prefer Expo Haptics / native haptics APIs.

🔧 Core concepts

APIRole
Vibration.vibrate()Default buzz
Vibration.vibrate(ms)Duration (Android)
Vibration.vibrate(pattern)Android pattern [wait, buzz, …]
Vibration.cancel()Stop
iOSDuration often ignored; pattern limited

Permissions: generally none for basic vibrate; respect user settings.

💡 Examples

import { Vibration, Pressable, Text, Platform } from "react-native";

export function BuzzButton() {
  return (
    <Pressable
      onPress={() => {
        if (Platform.OS === "android") {
          Vibration.vibrate([0, 50, 40, 50]);
        } else {
          Vibration.vibrate();
        }
      }}
    >
      <Text>Buzz</Text>
    </Pressable>
  );
}

⚠️ Pitfalls

  • Overusing vibration → annoying / battery drain.
  • Expecting Android patterns to feel identical on iOS.
  • Using Vibration when Haptics impact/selection is more appropriate.
  • Not cancelling long patterns on unmount.

On this page