react-view-pager icon indicating copy to clipboard operation
react-view-pager copied to clipboard

Carousel with links - Prevent link follow if swiping

Open bnhovde opened this issue 7 years ago • 2 comments

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?

bnhovde avatar Mar 16 '17 09:03 bnhovde

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.

souporserious avatar Mar 16 '17 17:03 souporserious

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>
))}

mdarens avatar Apr 11 '17 18:04 mdarens