设置不透明度的音量在 React-Native 中手动按下可触摸不透明度



我正在尝试弄清楚如何更改 React-Native 的可触摸不透明度组件的不透明度的体积,这意味着我不喜欢执行印刷时不透明度的默认值,并且我希望不透明度降低。

根据用于此目的的文档,应使用动画 API:

通过将子级包装在添加到视图层次结构中的 Animated.View 中来控制不透明度。请注意,这可能会影响布局。

所以,我做到了,这就是它的样子:

<Animated.View style={{ opacity: this.state.opacity._value }}>
<TouchableOpacity 
onPress={this.hideKeyboard.bind(this)}
style={{ opacity: this.state.opacity._value }}
>
<Text style={buttonTextStyle}>Cancel</Text>
</TouchableOpacity>
</Animated.View>

在Press上调用的hideKeyboard方法从其中调用changeOpacity方法,这就是它的外观:

changeOpacity() {
Animated.timing(
this.state.opacity, 
{
toValue: this.state.opacity === 1 ? 0 : 1,
duration: 500
}
).start();
}

this.state.opacity在构造函数中声明:

constructor(props) {
super(props);
this.state = { opacity: new Animated.Value(1) };
}

有了所有这些,行为(可触摸不透明度的不透明度的音量(不会改变,它仍然是默认的。该文档还模糊地介绍了setOpacityTo方法,但由于文档中提供的描述的彻底性,我无法弄清楚如何使用它。如何执行不透明度的手动配置?

你试过这个吗

<TouchableOpacity 
activeOpacity={.7} // default is .2
... other props here
/>

最新更新