react-native-maps 1.21.0-alpha.73 → 1.21.0-alpha.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,7 +105,7 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
105
105
  options.maxZoomPreference(initialProps.getInt("maxZoom", 0));
106
106
  }
107
107
  }
108
- if (initialProps.hasKey("userInterfaceStyle")){
108
+ if (initialProps.hasKey("userInterfaceStyle") && !initialProps.hasKey("liteMode")){
109
109
  String style = initialProps.getString("userInterfaceStyle");
110
110
  if ("system".equals(style)) {
111
111
  options.mapColorScheme(MapColorScheme.FOLLOW_SYSTEM);
@@ -2,13 +2,16 @@ package com.rnmaps.maps;
2
2
 
3
3
  import static androidx.core.content.PermissionChecker.checkSelfPermission;
4
4
 
5
+ import android.app.Activity;
5
6
  import android.content.Context;
6
7
  import android.content.res.ColorStateList;
7
8
  import android.graphics.Bitmap;
8
9
  import android.graphics.Color;
9
10
  import android.graphics.Point;
10
11
  import android.location.Location;
11
- import android.util.Log;
12
+ import androidx.lifecycle.DefaultLifecycleObserver;
13
+ import androidx.lifecycle.LifecycleOwner;
14
+
12
15
  import android.view.GestureDetector;
13
16
  import android.view.MotionEvent;
14
17
  import android.view.View;
@@ -26,7 +29,6 @@ import androidx.core.view.MotionEventCompat;
26
29
  import com.facebook.react.common.MapBuilder;
27
30
 
28
31
  import com.facebook.react.bridge.Arguments;
29
- import com.facebook.react.bridge.LifecycleEventListener;
30
32
  import com.facebook.react.bridge.ReactApplicationContext;
31
33
  import com.facebook.react.bridge.ReactContext;
32
34
  import com.facebook.react.bridge.ReadableArray;
@@ -84,7 +86,7 @@ import java.util.concurrent.ExecutionException;
84
86
  import com.rnmaps.fabric.event.*;
85
87
 
86
88
  public class MapView extends com.google.android.gms.maps.MapView implements GoogleMap.InfoWindowAdapter,
87
- GoogleMap.OnMarkerDragListener, OnMapReadyCallback, GoogleMap.OnPoiClickListener, GoogleMap.OnIndoorStateChangeListener {
89
+ GoogleMap.OnMarkerDragListener, OnMapReadyCallback, GoogleMap.OnPoiClickListener, GoogleMap.OnIndoorStateChangeListener, DefaultLifecycleObserver {
88
90
  public GoogleMap map;
89
91
  private MarkerManager markerManager;
90
92
  private MarkerManager.Collection markerCollection;
@@ -136,7 +138,6 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
136
138
  private final Map<TileOverlay, MapHeatmap> heatmapMap = new HashMap<>();
137
139
  private final Map<TileOverlay, MapGradientPolyline> gradientPolylineMap = new HashMap<>();
138
140
  private final GestureDetectorCompat gestureDetector;
139
- private LifecycleEventListener lifecycleListener;
140
141
  private boolean paused = false;
141
142
  private boolean destroyed = false;
142
143
  private final ThemedReactContext context;
@@ -188,13 +189,65 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
188
189
  return superContext;
189
190
  }
190
191
 
192
+
193
+ @Override
194
+ public void onCreate(LifecycleOwner owner) {
195
+ super.onCreate(null);
196
+ }
197
+
198
+ @Override
199
+ public void onStart(LifecycleOwner owner) {
200
+ super.onStart();
201
+ }
202
+ @Override
203
+ public void onResume(LifecycleOwner owner) {
204
+ if (hasPermissions() && map != null) {
205
+ //noinspection MissingPermission
206
+ map.setMyLocationEnabled(showUserLocation);
207
+ map.setLocationSource(fusedLocationSource);
208
+ }
209
+ synchronized (MapView.this) {
210
+ if (!destroyed) {
211
+ MapView.this.onResume();
212
+ }
213
+ paused = false;
214
+ }
215
+ }
216
+
217
+
218
+ @Override
219
+ public void onPause(LifecycleOwner owner){
220
+ super.onPause();
221
+ if (hasPermissions() && map != null) {
222
+ //noinspection MissingPermission
223
+ map.setMyLocationEnabled(false);
224
+ }
225
+ synchronized (MapView.this) {
226
+ if (!destroyed) {
227
+ MapView.this.onPause();
228
+ }
229
+ paused = true;
230
+ }
231
+ }
232
+
233
+ @Override
234
+ public void onStop(LifecycleOwner owner) {
235
+ super.onStop();
236
+ }
237
+
238
+ @Override
239
+ public void onDestroy(LifecycleOwner owner){
240
+ MapView.this.doDestroy();
241
+ }
242
+
191
243
  public MapView(ThemedReactContext context,
192
244
  GoogleMapOptions googleMapOptions) {
193
245
  super(context, googleMapOptions);
194
- // todo add support for legacy renderer
195
246
  this.context = context;
196
- super.onCreate(null);
197
- super.onResume();
247
+ Activity activity = context.getCurrentActivity();
248
+ if (activity instanceof LifecycleOwner) {
249
+ ((LifecycleOwner) activity).getLifecycle().addObserver(this);
250
+ }
198
251
  super.getMapAsync(this);
199
252
 
200
253
  final MapView view = this;
@@ -522,50 +575,8 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
522
575
  MapView.this.cacheView();
523
576
  });
524
577
 
525
- // We need to be sure to disable location-tracking when app enters background, in-case some
526
- // other module
527
- // has acquired a wake-lock and is controlling location-updates, otherwise, location-manager
528
- // will be left
529
- // updating location constantly, killing the battery, even though some other location-mgmt
530
- // module may
531
- // desire to shut-down location-services.
532
- lifecycleListener = new LifecycleEventListener() {
533
- @Override
534
- public void onHostResume() {
535
- if (hasPermissions() && map != null) {
536
- //noinspection MissingPermission
537
- map.setMyLocationEnabled(showUserLocation);
538
- map.setLocationSource(fusedLocationSource);
539
- }
540
- synchronized (MapView.this) {
541
- if (!destroyed) {
542
- MapView.this.onResume();
543
- }
544
- paused = false;
545
- }
546
- }
547
-
548
- @Override
549
- public void onHostPause() {
550
- if (hasPermissions() && map != null) {
551
- //noinspection MissingPermission
552
- map.setMyLocationEnabled(false);
553
- }
554
- synchronized (MapView.this) {
555
- if (!destroyed) {
556
- MapView.this.onPause();
557
- }
558
- paused = true;
559
- }
560
- }
561
578
 
562
- @Override
563
- public void onHostDestroy() {
564
- MapView.this.doDestroy();
565
- }
566
- };
567
579
 
568
- context.addLifecycleEventListener(lifecycleListener);
569
580
  isMapReady = true;
570
581
  if (kmlSrc != null){
571
582
  setKmlSrc(kmlSrc);
@@ -647,9 +658,9 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
647
658
  }
648
659
  destroyed = true;
649
660
 
650
- if (lifecycleListener != null && context != null) {
651
- context.removeLifecycleEventListener(lifecycleListener);
652
- lifecycleListener = null;
661
+ Activity activity = context.getCurrentActivity();
662
+ if (activity instanceof LifecycleOwner) {
663
+ ((LifecycleOwner) activity).getLifecycle().removeObserver(this);
653
664
  }
654
665
  if (!paused) {
655
666
  onPause();
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "main": "lib/index.js",
6
6
  "author": "Leland Richardson <leland.m.richardson@gmail.com>",
7
7
  "homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8
- "version": "1.21.0-alpha.73",
8
+ "version": "1.21.0-alpha.74",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",