现在,当我非常快速地按下我的touchableopacitys时,它会叠加一堆对onpress回调的调用,然后随着时间的推移执行它们。我想要的是能够防止进一步的回调,同时“触摸”或“褪色”,这样每次触摸容量“下降”时,只会调用一次on,即一个完整的循环淡出然后再返回我怎么会这样做?
答案 0 :(得分:0)
我认为你想要做的就是限制你的新闻回调,这样他们只能运行一次。你可以使用throttling
和underscore
库:例如:
class MyComponent extends React.Component {
constructor(props) {
super(props);
_.throttle(
this.onPressThrottle.bind(this),
200, // no new clicks within 200ms time window
);
}
onPressThrottle() {
// this only runs once per 200 milliseconds
}
render() {
return (
<View>
<TouchableOpacity onPress={this.onPressThrottle}>
</TouchableOpacity>
</View>
)
}
}