TouchableHighlight 的孩子在媒体上失去了不透明样式 [英] Child of TouchableHighlight loses opacity styling on press
问题描述
当 TouchableHighlight 的孩子具有不透明度时,按下 TouchableHighlight 后,其不透明度消失(设置为 1).
When a child of a TouchableHighlight has an opacity, its opacity disappears (is set to 1) after the TouchableHighlight is pressed.
在此处运行示例:https://rnplay.org/apps/c0NIjQ
最小示例:
<TouchableHighlight onPress={() => {}}>
<Text style={{ opacity: 0.5 }}>
Press me!
</Text>
</TouchableHighlight>
有没有办法解决这个问题,或者是 React Native 中的一个错误?
Is there a way to mend this, or is it a bug in React Native?
推荐答案
TouchableOpacity 像我对 TouchableHighlight 所期望的那样工作(实时代码示例),所以使用 TouchableOpacity 可以成为一种解决方法.请注意,但是,TouchableOpacity 没有在活动时出现的底图,因此无论您在下方渲染什么,都会在印刷时透出".因此,它不是 TouchableHighlight 的完美替代品.
TouchableOpacity works as I would have expected for TouchableHighlight (live code sample), so using TouchableOpacity could be a workaround. Note, however, that TouchableOpacity does not have an underlay which appears when active, so whatever you render underneath is what will "shine through" on press. Thus, it's not a perfect substitute for TouchableHighlight.
我不确定 TouchableHighlight 的行为是有意为之,某种权衡还是实际上是一个错误,但查看代码您可以清楚地看到它在这方面与 TouchableOpacity 有何不同:
I'm not sure whether the behavior of TouchableHighlight is intended, some sort of a tradeoff or actually a bug, but looking at the code you can clearly see how it differs from TouchableOpacity in this regard:
- TouchableHighlight always sets the child's opacity to 1 when it goes inactive.
- TouchableOpacity sets the child's opacity to
childStyles.opacity
if it is set, otherwise 1, when it goes inactive.
这篇关于TouchableHighlight 的孩子在媒体上失去了不透明样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!