Code Reference

Pressable

React Native · Reference cheat sheet

Pressable

React Native · Reference cheat sheet


📋 Overview

Pressable is the modern press handler—prefer it over TouchableOpacity / TouchableHighlight. Style from press state, configure hit slop, and set accessibility roles. See also touchable.md for legacy touchables.

🔧 Core concepts

  • EventsonPress, onLongPress, onPressIn / Out.
  • State stylestyle=\{(\{ pressed \}) => ...\}.
  • hitSlop — expand touch target.
  • android_ripple — Material ripple.
  • disabled — block interaction + a11y state.
  • DelaydelayLongPress.

💡 Examples

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

export function Button({
  label,
  onPress,
  disabled,
}: {
  label: string;
  onPress: () => void;
  disabled?: boolean;
}) {
  return (
    <Pressable
      accessibilityRole="button"
      accessibilityState={{ disabled: !!disabled }}
      disabled={disabled}
      hitSlop={8}
      android_ripple={{ color: "#ffffff55" }}
      onPress={onPress}
      style={({ pressed }) => [
        styles.btn,
        pressed && styles.pressed,
        disabled && styles.disabled,
      ]}
    >
      <Text style={styles.label}>{label}</Text>
    </Pressable>
  );
}

const styles = StyleSheet.create({
  btn: {
    backgroundColor: "#111",
    paddingVertical: 12,
    paddingHorizontal: 16,
    borderRadius: 8,
  },
  pressed: { opacity: 0.85 },
  disabled: { opacity: 0.4 },
  label: { color: "#fff", fontWeight: "600", textAlign: "center" },
});

⚠️ Pitfalls

  • Touch targets under ~44×44 pt.
  • Nested Pressables competing for gestures.
  • Using Touchable* in new code without reason.
  • Missing accessibilityRole="button".

On this page