diff --git a/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java b/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java index b31106dca..4273a31ed 100644 --- a/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java +++ b/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java @@ -72,12 +72,6 @@ protected AirMapView createViewInstance(ThemedReactContext context) { return new AirMapView(context, this.appContext.getCurrentActivity(), this, this.googleMapOptions); } - @Override - public void onDropViewInstance(AirMapView view) { - view.doDestroy(); - super.onDropViewInstance(view); - } - private void emitMapError(String message, String type) { WritableMap error = Arguments.createMap(); error.putString("message", message); diff --git a/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index faae1a002..e381757c8 100644 --- a/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -39,7 +39,6 @@ import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.Marker; -import com.google.android.gms.maps.model.TileOverlay; import java.util.ArrayList; import java.util.Arrays; @@ -76,16 +75,16 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter, private final ScaleGestureDetector scaleDetector; private final GestureDetectorCompat gestureDetector; private final AirMapManager manager; - private LifecycleEventListener lifecycleListener; private boolean paused = false; private final ThemedReactContext context; private final EventDispatcher eventDispatcher; - public AirMapView(ThemedReactContext context, Context appContext, AirMapManager manager, GoogleMapOptions googleMapOptions) { + public AirMapView(ThemedReactContext reactContext, Context appContext, AirMapManager manager, + GoogleMapOptions googleMapOptions) { super(appContext, googleMapOptions); this.manager = manager; - this.context = context; + this.context = reactContext; super.onCreate(null); super.onResume(); @@ -93,7 +92,7 @@ public AirMapView(ThemedReactContext context, Context appContext, AirMapManager final AirMapView view = this; scaleDetector = - new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() { + new ScaleGestureDetector(reactContext, new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScaleBegin(ScaleGestureDetector detector) { view.startMonitoringRegion(); @@ -102,7 +101,7 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { }); gestureDetector = - new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() { + new GestureDetectorCompat(reactContext, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTap(MotionEvent e) { view.startMonitoringRegion(); @@ -123,13 +122,13 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, this.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { - if (!AirMapView.this.paused) { + if (!paused) { AirMapView.this.cacheView(); } } }); - eventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher(); + eventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); } @Override @@ -230,36 +229,32 @@ public void onCameraChange(CameraPosition position) { // updating location constantly, killing the battery, even though some other location-mgmt // module may // desire to shut-down location-services. - lifecycleListener = new LifecycleEventListener() { - @Override - public void onHostResume() { - if (hasPermissions()) { - //noinspection MissingPermission - map.setMyLocationEnabled(showUserLocation); - } - synchronized (AirMapView.this) { - AirMapView.this.onResume(); - paused = false; - } - } + LifecycleEventListener lifecycleListener = new LifecycleEventListener() { + @Override + public void onHostResume() { + if (hasPermissions()) { + //noinspection MissingPermission + map.setMyLocationEnabled(showUserLocation); + } + synchronized (AirMapView.this) { + AirMapView.this.onResume(); + paused = false; + } + } - @Override - public void onHostPause() { - if (hasPermissions()) { - //noinspection MissingPermission - map.setMyLocationEnabled(false); - } - synchronized (AirMapView.this) { - AirMapView.this.onPause(); - paused = true; - } - } + @Override + public void onHostPause() { + if (hasPermissions()) { + //noinspection MissingPermission + map.setMyLocationEnabled(false); + } + paused = true; + } - @Override - public void onHostDestroy() { - AirMapView.this.doDestroy(); - } - }; + @Override + public void onHostDestroy() { + } + }; context.addLifecycleEventListener(lifecycleListener); } @@ -269,20 +264,6 @@ private boolean hasPermissions() { checkSelfPermission(getContext(), PERMISSIONS[1]) == PackageManager.PERMISSION_GRANTED; } - /* - onDestroy is final method so I can't override it. - */ - public synchronized void doDestroy() { - if (lifecycleListener != null) { - context.removeLifecycleEventListener(lifecycleListener); - lifecycleListener = null; - } - if (!paused) { - onPause(); - } - onDestroy(); - } - public void setRegion(ReadableMap region) { if (region == null) return; diff --git a/example/android/build.gradle b/example/android/build.gradle index cc73e1e1e..b249b0409 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:2.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files