react-view-pager
react-view-pager copied to clipboard
Carousel with links - Prevent link follow if swiping
Hi,
Great plugin. I'm wondering if you've come across a case where you have links in the carousel?
What I'm facing now is the links are triggered on swipe, and I'm not sure if there's a simple way to prevent this behaviour?
Ah dang, this is definitely a bug. I'm guessing we need to check on touchStart
if it was a link or not and maybe preventDefault
or something. I'll look into this as soon as I get a chance. If for some reason you figure it out in the mean time, I can help you work through a PR.
Here's the workaround I'm using:
In my class properties
state = {
enableLinks: true
}
handleScroll = () => {
this.setState({
enableLinks: false
});
}
handleRest = () => {
this.setState({
enableLinks: true
});
}
handleViewClick = e => {
if (this.state.enableLinks) {
return true;
}
e.preventDefault();
}
in my render method
{someCollection.map(({ id, ...props }) => (
<View key={id} onClick={this.handleViewClick}>
<MyLinkComponent {...props} />
</View>
))}