import React from 'react';
import { View, Button, Pressable, Text, Alert, StyleSheet } from 'react-native';
export default function ButtonPressableDemo() {
return (
<View style={styles.container}>
<Button
title="Click Me Button"
onPress={() => Alert.alert('Button pressed!')}
/>
<Pressable
onPress={() => Alert.alert('Pressable pressed!')}
style={({ pressed }) => [
styles.pressable,
{ backgroundColor: pressed ? '#ddd' : '#eee' }
]}
android_ripple={{ color: '#aaa' }}
accessibilityRole="button"
accessibilityLabel="Press Me Pressable"
>
<Text style={styles.pressableText}>Press Me Pressable</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20
},
pressable: {
marginTop: 20,
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 8
},
pressableText: {
fontSize: 16,
color: '#000'
}
});We use the built-in Button component for a simple clickable button that shows an alert on press.
For the Pressable, we add a Text inside and style it with padding and rounded corners. The style prop uses a function to change background color when pressed, giving visual feedback.
We also add android_ripple for ripple effect on Android and accessibility props for screen readers.
This shows how to use both components for clickable UI elements with feedback.