Skip to the workspace
Pebellslearn by building
Core Components  ›  Lesson

Pressable, Button and Switch

Button 12 minButton is a quick platform-styled action, Pressable makes any content touchable with full control over its look and press feedback, and Switch is a controlled on/off toggle.

react native / Pressable, Button and Switch

Explore each scene at your own pace.

01 · The rule

The rule

Pressable, Button and Switch

Sprout needs three kinds of touch: a quick "Watered" button, a whole plant card you can tap to open, and an on/off setting for reminders. React Native has a component for each, and choosing the right one decides how much control you get over the look.

The rule

Button for quick, Pressable for custom, Switch for on and off.

Button is the simplest. It draws the platform's standard button and accepts very little styling:

<Button title="Watered" onPress={markWatered} color="#2e7d32" />

It takes a title string, an onPress function, a color and a disabled flag. You cannot give it a custom shape or padding, so real apps soon outgrow it.

Pressable wraps anything and makes it respond to touch. Its style can be a function that receives { pressed }, so you can show feedback while the finger is down:

<Pressable
  onPress={() => openPlant(plant.id)}
  onLongPress={() => askToDelete(plant.id)}
  hitSlop={8}
  style={({ pressed }) => [styles.card, pressed && { opacity: 0.6 }]}
>
  <Text>{plant.name}</Text>
</Pressable>
  • onPress fires on a normal tap; onLongPress fires when held (about half a second by default).
  • hitSlop enlarges the touchable area beyond the visible box, which helps small icons.
  • Older code uses TouchableOpacity and similar Touchables. They still work, but Pressable is the more flexible, recommended choice for new code.

Switch is a toggle. Like a controlled input, it shows a value and reports changes:

const [remind, setRemind] = useState(true);

<Switch value={remind} onValueChange={setRemind} />

onValueChange receives the new boolean. If you forget to update state, the switch snaps back, because value still says the old thing.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.