Disable onRegionChange events when not in use

This commit is contained in:
Marius Petcu
2016-07-02 20:00:22 +03:00
parent c88762e8ac
commit 6ed0187426
3 changed files with 28 additions and 2 deletions
@@ -55,6 +55,8 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
private boolean _zoomEnabled = true;
private boolean _scrollEnabled = true;
private boolean _rotateEnabled = true;
private boolean _enableOnRegionWillChange = false;
private boolean _enableOnRegionDidChange = false;
private int _paddingTop, _paddingRight, _paddingBottom, _paddingLeft;
private android.os.Handler _trackingModeHandler;
@@ -188,6 +190,14 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
_initialCamera.target(new LatLng(lat, lon));
}
public void setEnableOnRegionDidChange(boolean value) {
_enableOnRegionDidChange = value;
}
public void setEnableOnRegionWillChange(boolean value) {
_enableOnRegionWillChange = value;
}
public void setShowsUserLocation(boolean value) {
if (_showsUserLocation == value) { return; }
_showsUserLocation = value;
@@ -407,11 +417,15 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
switch (change) {
case MapView.REGION_WILL_CHANGE:
case MapView.REGION_WILL_CHANGE_ANIMATED:
emitEvent("onRegionWillChange", serializeCurrentRegion()); // TODO: These should be throttled
if (_enableOnRegionWillChange) {
emitEvent("onRegionWillChange", serializeCurrentRegion()); // TODO: These should be throttled
}
break;
case MapView.REGION_DID_CHANGE:
case MapView.REGION_DID_CHANGE_ANIMATED:
emitEvent("onRegionDidChange", serializeCurrentRegion());
if (_enableOnRegionDidChange) {
emitEvent("onRegionDidChange", serializeCurrentRegion());
}
break;
case MapView.WILL_START_LOADING_MAP:
emitEvent("onStartLoadingMap", null);