I have a TouchableHighlight wrapping a Text block that when tapped, opens a new scene (which I\'m using react-native-router-flux).
It\'s all wo
What you're trying to do is you want to limit your on tap callbacks, so that they will only run ONCE.
This is called throttling, and you can use underscore for that:
Here's how:
_.throttle(
this.thisWillRunOnce.bind(this),
200, // no new clicks within 200ms time window
);
Here's how my react component looks after all.
class MyComponent extends React.Component {
constructor(props) {
super(props);
_.throttle(
this.onPressThrottledCb.bind(this),
200, // no new clicks within 200ms time window
);
}
onPressThrottledCb() {
if (this.props.onPress) {
this.props.onPress(); // this only runs once per 200 milliseconds
}
}
render() {
return (
)
}
}
I hope this helps you. In case you wanna learn more check this thread.