react native 有没有像 onPressAndHold 这样的东西?
Is there something like onPressAndHold in react native?
我在 React Native 中制作了一个自定义数字计数器:当您按下 + 时,它会增加状态;当您按下 - 时,它会减少状态值;问题是,对于某人从 0 到 60,使用 onPress 需要很长时间,有什么我可以用来长按的东西吗?
onLongPress 无效,谢谢。
你可以使用这个
<TouchableOpacity onPressIn={this.addOne} onPressOut={this.stopTimer}>
<Icon name="plus-circle" size={30} color={'white'} />
</TouchableOpacity>
constructor() {
super();
this.state = {
number: 0,
};
this.timer = null;
this.addOne = this.addOne.bind(this);
this.stopTimer = this.stopTimer.bind(this);
}
addOne() {
this.setState({number: this.state.number+1});
this.timer = setTimeout(this.addOne, 200);
}
stopTimer() {
clearTimeout(this.timer);
}
我在 React Native 中制作了一个自定义数字计数器:当您按下 + 时,它会增加状态;当您按下 - 时,它会减少状态值;问题是,对于某人从 0 到 60,使用 onPress 需要很长时间,有什么我可以用来长按的东西吗?
onLongPress 无效,谢谢。
你可以使用这个
<TouchableOpacity onPressIn={this.addOne} onPressOut={this.stopTimer}>
<Icon name="plus-circle" size={30} color={'white'} />
</TouchableOpacity>
constructor() {
super();
this.state = {
number: 0,
};
this.timer = null;
this.addOne = this.addOne.bind(this);
this.stopTimer = this.stopTimer.bind(this);
}
addOne() {
this.setState({number: this.state.number+1});
this.timer = setTimeout(this.addOne, 200);
}
stopTimer() {
clearTimeout(this.timer);
}