This app shows a basic Button and a Pressable. Tapping either shows an alert. The Pressable changes color when pressed.
import React from 'react';
import { View, Button, Pressable, Text, Alert, StyleSheet } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Button
title="Click Button"
onPress={() => Alert.alert('Button pressed!')}
/>
<Pressable
onPress={() => Alert.alert('Pressable pressed!')}
style={({ pressed }) => [
styles.pressable,
{ backgroundColor: pressed ? '#ddd' : '#eee' }
]}
accessibilityLabel="Pressable button"
>
<Text style={styles.text}>Press Me</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20
},
pressable: {
marginTop: 20,
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 5
},
text: {
fontSize: 18,
color: '#333'
}
});