Create map after first transaction

This commit is contained in:
Marius Petcu
2016-07-02 18:51:09 +03:00
parent a12721cb3e
commit d6379803e5
2 changed files with 37 additions and 27 deletions
@@ -51,6 +51,17 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager<ReactNativeMap
return new ReactNativeMapboxGLView(context, this);
}
@Override
protected void onAfterUpdateTransaction(ReactNativeMapboxGLView view) {
super.onAfterUpdateTransaction(view);
view.onAfterUpdateTransaction();
}
@Override
public void onDropViewInstance(ReactNativeMapboxGLView view) {
view.onDrop();
}
// Props
@ReactProp(name = "initialZoomLevel")
@@ -73,28 +73,23 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
// Lifecycle methods
@Override
public void onAttachedToWindow () {
super.onAttachedToWindow();
if (_mapView == null) {
setupMapView();
}
public void onAfterUpdateTransaction() {
if (_mapView != null) { return; }
setupMapView();
_paused = false;
_mapView.onResume();
_manager.getContext().addLifecycleEventListener(this);
}
@Override
public void onDetachedFromWindow () {
if (_mapView != null) {
if (!_paused) {
_paused = true;
_mapView.onPause();
}
_mapView.onDestroy();
}
public void onDrop() {
if (_mapView == null) { return; }
_manager.getContext().removeLifecycleEventListener(this);
super.onDetachedFromWindow();
if (!_paused) {
_paused = true;
_mapView.onPause();
}
destroyMapView();
_mapView = null;
}
@Override
@@ -111,17 +106,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
@Override
public void onHostDestroy() {
_mapView.removeOnMapChangedListener(this);
if (_map != null) {
_map.setOnMapClickListener(null);
_map.setOnMapLongClickListener(null);
_map.setOnMyLocationTrackingModeChangeListener(null);
_map.setOnMyBearingTrackingModeChangeListener(null);
_map.setOnMyLocationChangeListener(null);
_map = null;
}
_mapView.onDestroy();
_mapView = null;
onDrop();
}
// Initialization
@@ -137,6 +122,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
@Override
public void onMapReady(MapboxMap mapboxMap) {
if (_mapView == null) { return; }
_map = mapboxMap;
// Configure map
@@ -175,6 +161,19 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements
_map.setOnMyLocationChangeListener(this);
}
private void destroyMapView() {
_mapView.removeOnMapChangedListener(this);
if (_map != null) {
_map.setOnMapClickListener(null);
_map.setOnMapLongClickListener(null);
_map.setOnMyLocationTrackingModeChangeListener(null);
_map.setOnMyBearingTrackingModeChangeListener(null);
_map.setOnMyLocationChangeListener(null);
_map = null;
}
_mapView.onDestroy();
}
// Props
public void setInitialZoomLevel(double value) {