[英]How to change text color when Pressable pressed
I have a Pressable with a Text inside and i want to change the color of the text when the pressable is pressed (it is ok for Pressable's backgourndcolor but not for Text) I tried something like:我有一个 Pressable 里面有一个文本,我想在按下 pressable 时更改文本的颜色(对于 Pressable 的 backgourndcolor 是可以的,但对于 Text 则不行)我尝试了类似的方法:
<Pressable
style={({ pressed }) => [
{
backgroundColor: pressed
? colors.PRIMARY_COLOR_DARK
: colors.MAIN_BACKGROUND,
},
styles.playVideosButton,
]}
onPress={() => console.log("Dossier")}>
{({ pressed }) => {
<Text
style={[
{
color: pressed
? colors.WHITE_TEXT
: colors.PRIMARY_COLOR_DARK,
},
styles.buttonText,
]}>
Lancer les vidéos
</Text>;
}}
</Pressable>
With this code Text desappears使用此代码文本消失
Apologies after more thorough testing the original script worked - as long as there are no color changes inside styles.buttonText.抱歉,经过更彻底的测试,原始脚本可以正常工作 - 只要 styles.buttonText 中没有颜色变化。
{({ pressed }) => (
<Text
style={[
{
color: pressed
? colors.WHITE_TEXT
: colors.PRIMARY_COLOR_DARK,
},
styles.buttonText,
]}>
Dossier
</Text>
)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.