Skip to content

Commit

Permalink
Fix ipad dragging issue (#233)
Browse files Browse the repository at this point in the history
* Fix ipad dragging issue

* Limit touch events to map only
  • Loading branch information
jooj123 authored and istarkov committed Sep 1, 2016
1 parent 9d45cc3 commit 7d1180c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/google_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ export default class GoogleMap extends Component {
this.mounted_ = true;
window.addEventListener('resize', this._onWindowResize);
window.addEventListener('keydown', this._onKeyDownCapture, true);

// prevent touch devices from moving the entire browser window on drag
window.addEventListener('touchmove', this._onTouchMove);

const mapDom = ReactDOM.findDOMNode(this.refs.google_map_dom);
// gmap can't prevent map drag if mousedown event already occured
// the only workaround I find is prevent mousedown native browser event
Expand Down Expand Up @@ -313,6 +317,7 @@ export default class GoogleMap extends Component {
window.removeEventListener('keydown', this._onKeyDownCapture);
mapDom.removeEventListener('mousedown', this._onMapMouseDownNative, true);
window.removeEventListener('mouseup', this._onChildMouseUp, false);
window.removeEventListener('touchmove', this._onTouchMove);
detectElementResize.addResizeListener(mapDom, that._mapDomResizeCallback);

if (this.overlay_) {
Expand Down Expand Up @@ -814,6 +819,15 @@ export default class GoogleMap extends Component {
}
}

_onTouchMove = (event) => {
if (this.refs.google_map_dom) {
const mapDom = ReactDOM.findDOMNode(this.refs.google_map_dom);
if (mapDom.contains(event.target)) {
event.preventDefault();
}
}
}

_isCenterDefined = (center) => center && (
(isPlainObject(center) && isNumber(center.lat) && isNumber(center.lng)) ||
(center.length === 2 && isNumber(center[0]) && isNumber(center[1]))
Expand Down

0 comments on commit 7d1180c

Please sign in to comment.