【发布时间】:2022-01-06 21:32:40
【问题描述】:
我试图在用户单击按钮时更改按钮的不透明度,(在 2 个按钮之间,较暗的一个将是他的选择)。出于某种原因,每当我单击按钮时,不透明度不会改变,并且仅在单击 2 次后才会改变。任何想法我哪里出错了?
export default function lastName({ navigation }) {
let [opac, setOpacity] = useState(0.3);
return (
<View style={styles.container}>
<View
style={{
flex: 0.5,
justifyContent: "flex-end",
//backgroundColor: "red",
}}
>
<Text style={styles.textStyle}>
Select a button
</Text>
</View>
<View
style={{
flex: 1,
justifyContent: "flex-start",
}}
>
<TouchableOpacity
style={{
marginTop: 70,
alignItems: "center",
justifyContent: "center",
width: 180,
height: 40,
backgroundColor: "#004953",
opacity: opac,/// here
borderRadius: 100,
}}
onPress={() => {
setOpacity(1); // here
}}
>
<Text
style={{
color: "white",
textAlign: "center",
fontSize: 18,
}}
>
Button 1
</Text>
</TouchableOpacity>
【问题讨论】:
标签: react-native touchableopacity