TouchableOpacity is a React Native component used to make any view respond to touch events by reducing its opacity when pressed.
onPressThe component wraps child elements and triggers an action when pressed.
// Basic TouchableOpacity structure
<TouchableOpacity onPress={handlePress}>
<Text>Click Me</Text>
</TouchableOpacity>
// Simple button using TouchableOpacity
import React from "react";
import { View, Text, TouchableOpacity } from "react-native";
export default function App() {
return (
<View>
<TouchableOpacity onPress={() => alert("Button Pressed")}>
<Text>Press Here</Text>
</TouchableOpacity>
</View>
);
}
When the user taps the text, the opacity reduces briefly and an alert message appears.
Imagine a mobile button that fades when touched — this feedback improves user experience.
Click or Tap the items below to see the opacity change in action:
activeOpacity to control fade intensityTouchableOpacityactiveOpacity