import React, { useState } from 'react'; import { View, StyleSheet, TextInput, Button } from 'react-native'; const App = () => { const [textColor, setTextColor] = useState('black'); const handleBlueButtonClick = () => { setTextColor('blue'); }; const handleGreenButtonClick = () => { setTextColor('green'); }; return ( <View style={styles.container}> <TextInput style={[styles.input, { color: textColor }]} placeholder="Enter text..." /> <Button title="Blue" onPress={handleBlueButtonClick} /> <Button title="Green" onPress={handleGreenButtonClick} /> </View> ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, input: { width: '100%', height: 40, borderWidth: 1, borderColor: '#ccc', padding: 10, }, }); export default App;
|