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>onPressfires on a normal tap;onLongPressfires when held (about half a second by default).hitSlopenlarges the touchable area beyond the visible box, which helps small icons.- Older code uses
TouchableOpacityand similar Touchables. They still work, butPressableis 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.