React-Native의 Button은 styling이 제한적
Button을 사용하여 Color를 지정할 때
공식문서의 props를 보면 Color밖에 없으며
또한 버튼 안의 경우 title={} 형식으로 보내주기 때문에
글씨체 Color는 지정 불가
React-Native Button style not work
React-Native Button style not work
Import_this import {AppRegistry, Text, View, Button, StyleSheet} from 'react-native'; This my React Button code But style not working Hare ... <Button onPress={this.onPress.bind(this)} t...
stackoverflow.com
따라서 TouchableOpacity 대안으로 삼는다.
TouchableOpacity
TouchableOpacity · React Native
TouchableOpacity · React Native
If you're looking for a more extensive and future-proof way to handle touch-based input, check out the Pressable API.
reactnative.dev
Sample Code
import React, { useState } from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
const App = () => {
const [count, setCount] = useState(0);
const onPress = () => setCount(prevCount => prevCount + 1);
return (
<View style={styles.container}>
<View style={styles.countContainer}>
<Text>Count: {count}</Text>
</View>
<TouchableOpacity
style={styles.button}
onPress={onPress}
>
<Text>Press Here</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
paddingHorizontal: 10
},
button: {
alignItems: "center",
backgroundColor: "#DDDDDD",
padding: 10
},
countContainer: {
alignItems: "center",
padding: 10
}
});
export default App;
'Development > React-native' 카테고리의 다른 글
[React-Native] KeyboardAwareScrollView (0) | 2022.11.04 |
---|
댓글