react-native-maps 1.21.0-alpha.72 → 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;
@@ -99,6 +101,9 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
99
101
  private RelativeLayout mapLoadingLayout;
100
102
  private ImageView cacheImageView;
101
103
  private Boolean isMapLoaded = false;
104
+
105
+ private Boolean isMapReady = false;
106
+
102
107
  private Integer loadingBackgroundColor = null;
103
108
  private Integer loadingIndicatorColor = null;
104
109
 
@@ -133,7 +138,6 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
133
138
  private final Map<TileOverlay, MapHeatmap> heatmapMap = new HashMap<>();
134
139
  private final Map<TileOverlay, MapGradientPolyline> gradientPolylineMap = new HashMap<>();
135
140
  private final GestureDetectorCompat gestureDetector;
136
- private LifecycleEventListener lifecycleListener;
137
141
  private boolean paused = false;
138
142
  private boolean destroyed = false;
139
143
  private final ThemedReactContext context;
@@ -153,6 +157,7 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
153
157
  private Boolean showIndoors;
154
158
  private Boolean scrollEnabled;
155
159
  private Boolean scrollDuringRotateOrZoomEnabled;
160
+ private String kmlSrc = null;
156
161
 
157
162
  private static boolean contextHasBug(Context context) {
158
163
  return context == null ||
@@ -184,13 +189,65 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
184
189
  return superContext;
185
190
  }
186
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
+
187
243
  public MapView(ThemedReactContext context,
188
244
  GoogleMapOptions googleMapOptions) {
189
245
  super(context, googleMapOptions);
190
- // todo add support for legacy renderer
191
246
  this.context = context;
192
- super.onCreate(null);
193
- super.onResume();
247
+ Activity activity = context.getCurrentActivity();
248
+ if (activity instanceof LifecycleOwner) {
249
+ ((LifecycleOwner) activity).getLifecycle().addObserver(this);
250
+ }
194
251
  super.getMapAsync(this);
195
252
 
196
253
  final MapView view = this;
@@ -518,50 +575,13 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
518
575
  MapView.this.cacheView();
519
576
  });
520
577
 
521
- // We need to be sure to disable location-tracking when app enters background, in-case some
522
- // other module
523
- // has acquired a wake-lock and is controlling location-updates, otherwise, location-manager
524
- // will be left
525
- // updating location constantly, killing the battery, even though some other location-mgmt
526
- // module may
527
- // desire to shut-down location-services.
528
- lifecycleListener = new LifecycleEventListener() {
529
- @Override
530
- public void onHostResume() {
531
- if (hasPermissions() && map != null) {
532
- //noinspection MissingPermission
533
- map.setMyLocationEnabled(showUserLocation);
534
- map.setLocationSource(fusedLocationSource);
535
- }
536
- synchronized (MapView.this) {
537
- if (!destroyed) {
538
- MapView.this.onResume();
539
- }
540
- paused = false;
541
- }
542
- }
543
578
 
544
- @Override
545
- public void onHostPause() {
546
- if (hasPermissions() && map != null) {
547
- //noinspection MissingPermission
548
- map.setMyLocationEnabled(false);
549
- }
550
- synchronized (MapView.this) {
551
- if (!destroyed) {
552
- MapView.this.onPause();
553
- }
554
- paused = true;
555
- }
556
- }
557
-
558
- @Override
559
- public void onHostDestroy() {
560
- MapView.this.doDestroy();
561
- }
562
- };
563
579
 
564
- context.addLifecycleEventListener(lifecycleListener);
580
+ isMapReady = true;
581
+ if (kmlSrc != null){
582
+ setKmlSrc(kmlSrc);
583
+ kmlSrc = null;
584
+ }
565
585
  }
566
586
 
567
587
  private synchronized void handleMarkerSelection(MapMarker target) {
@@ -638,9 +658,9 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
638
658
  }
639
659
  destroyed = true;
640
660
 
641
- if (lifecycleListener != null && context != null) {
642
- context.removeLifecycleEventListener(lifecycleListener);
643
- lifecycleListener = null;
661
+ Activity activity = context.getCurrentActivity();
662
+ if (activity instanceof LifecycleOwner) {
663
+ ((LifecycleOwner) activity).getLifecycle().removeObserver(this);
644
664
  }
645
665
  if (!paused) {
646
666
  onPause();
@@ -1587,64 +1607,66 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
1587
1607
  }
1588
1608
 
1589
1609
  public void setKmlSrc(String kmlSrc) {
1590
- try {
1591
- InputStream kmlStream = new FileUtil(context).execute(kmlSrc).get();
1610
+ if (isMapReady) {
1611
+ try {
1612
+ InputStream kmlStream = new FileUtil(context).execute(kmlSrc).get();
1592
1613
 
1593
- if (kmlStream == null) {
1594
- return;
1595
- }
1614
+ if (kmlStream == null) {
1615
+ return;
1616
+ }
1596
1617
 
1597
- KmlLayer kmlLayer = new KmlLayer(map, kmlStream, context, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
1598
- kmlLayer.addLayerToMap();
1618
+ KmlLayer kmlLayer = new KmlLayer(map, kmlStream, context, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
1599
1619
 
1600
- WritableMap pointers = new WritableNativeMap();
1601
- WritableArray markers = new WritableNativeArray();
1620
+ kmlLayer.addLayerToMap();
1602
1621
 
1603
- if (kmlLayer.getContainers() == null) {
1604
- // todo: use Fabric events
1605
- // manager.pushEvent(context, this, "onKmlReady", pointers);
1606
- return;
1607
- }
1608
-
1609
- //Retrieve a nested container within the first container
1610
- KmlContainer container = kmlLayer.getContainers().iterator().next();
1611
- if (container == null || container.getContainers() == null) {
1612
- // todo: use Fabric events
1613
- // manager.pushEvent(context, this, "onKmlReady", pointers);
1614
- return;
1615
- }
1622
+ WritableMap pointers = new WritableNativeMap();
1623
+ WritableArray markers = new WritableNativeArray();
1616
1624
 
1625
+ if (kmlLayer.getContainers() == null) {
1626
+ // todo: use Fabric events
1627
+ // manager.pushEvent(context, this, "onKmlReady", pointers);
1628
+ return;
1629
+ }
1617
1630
 
1618
- if (container.getContainers().iterator().hasNext()) {
1619
- container = container.getContainers().iterator().next();
1620
- }
1631
+ //Retrieve a nested container within the first container
1632
+ KmlContainer container = kmlLayer.getContainers().iterator().next();
1633
+ if (container == null || container.getContainers() == null) {
1634
+ // todo: use Fabric events
1635
+ // manager.pushEvent(context, this, "onKmlReady", pointers);
1636
+ return;
1637
+ }
1621
1638
 
1622
- int index = 0;
1623
- for (KmlPlacemark placemark : container.getPlacemarks()) {
1624
- MarkerOptions options = new MarkerOptions();
1625
1639
 
1626
- if (placemark.getInlineStyle() != null) {
1627
- options = placemark.getMarkerOptions();
1628
- } else {
1629
- options.icon(BitmapDescriptorFactory.defaultMarker());
1640
+ if (container.getContainers().iterator().hasNext()) {
1641
+ container = container.getContainers().iterator().next();
1630
1642
  }
1631
1643
 
1632
- LatLng latLng = ((LatLng) placemark.getGeometry().getGeometryObject());
1633
- String title = "";
1634
- String snippet = "";
1644
+ int index = 0;
1645
+ for (KmlPlacemark placemark : container.getPlacemarks()) {
1646
+ MarkerOptions options = new MarkerOptions();
1635
1647
 
1636
- if (placemark.hasProperty("name")) {
1637
- title = placemark.getProperty("name");
1638
- }
1648
+ if (placemark.getInlineStyle() != null) {
1649
+ options = placemark.getMarkerOptions();
1650
+ } else {
1651
+ options.icon(BitmapDescriptorFactory.defaultMarker());
1652
+ }
1639
1653
 
1640
- if (placemark.hasProperty("description")) {
1641
- snippet = placemark.getProperty("description");
1642
- }
1654
+ LatLng latLng = ((LatLng) placemark.getGeometry().getGeometryObject());
1655
+ String title = "";
1656
+ String snippet = "";
1657
+
1658
+ if (placemark.hasProperty("name")) {
1659
+ title = placemark.getProperty("name");
1660
+ }
1661
+
1662
+ if (placemark.hasProperty("description")) {
1663
+ snippet = placemark.getProperty("description");
1664
+ }
1643
1665
 
1644
- options.position(latLng);
1645
- options.title(title);
1646
- options.snippet(snippet);
1647
- // FIXME: get markerManager from somewhere
1666
+ options.position(latLng);
1667
+ options.title(title);
1668
+ options.snippet(snippet);
1669
+ // FIXME: get markerManager from somewhere
1648
1670
  /*
1649
1671
  MapMarker marker = new MapMarker(context, options, this.manager.getMarkerManager());
1650
1672
 
@@ -1670,15 +1692,18 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
1670
1692
 
1671
1693
  markers.pushMap(loadedMarker);
1672
1694
  */
1673
- }
1695
+ }
1674
1696
 
1675
- pointers.putArray("markers", markers);
1676
- // todo: use Fabric events
1677
- // manager.pushEvent(context, this, "onKmlReady", pointers);
1697
+ pointers.putArray("markers", markers);
1698
+ // todo: use Fabric events
1699
+ // manager.pushEvent(context, this, "onKmlReady", pointers);
1678
1700
 
1679
- } catch (XmlPullParserException | IOException | InterruptedException |
1680
- ExecutionException e) {
1681
- e.printStackTrace();
1701
+ } catch (XmlPullParserException | IOException | InterruptedException |
1702
+ ExecutionException e) {
1703
+ e.printStackTrace();
1704
+ }
1705
+ } else {
1706
+ this.kmlSrc = kmlSrc;
1682
1707
  }
1683
1708
  }
1684
1709
 
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.72",
8
+ "version": "1.21.0-alpha.74",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",