Skip to content

Commit

Permalink
Fixes a nasty bug that breaks preventDefault
Browse files Browse the repository at this point in the history
calling preventDefault on the event received in onTap is currently broken on iOS. This fixes that.
  • Loading branch information
nmn committed Jul 23, 2015
1 parent f9ca4f7 commit a822fe9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Tappable.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ var Mixin = {
var movement = this.calculateMovement(this._lastTouch);
if (movement.x <= this.props.moveThreshold && movement.y <= this.props.moveThreshold && this.props.onTap) {
event.preventDefault();
event.preventDefault = function(){};
// calling preventDefault twice throws an error. This will fix that.
event.persist();
afterEndTouch = () => {
var finalParentScrollPos = this._scrollParents.map(node => node.scrollTop + node.scrollLeft);
Expand Down

2 comments on commit a822fe9

@slorber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JedWatson this is because of event pooling and calling onTap synchronously (or calling e.persist()) also fixes this problem.
See facebook/react#3657 (comment)

I opened my initial PR because of this issue

@slorber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.