react-native-maps 1.21.0-alpha.54 → 1.21.0-alpha.56
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.
|
@@ -3,13 +3,18 @@ package com.rnmaps.fabric;
|
|
|
3
3
|
|
|
4
4
|
import static com.rnmaps.maps.MapManager.MY_LOCATION_PRIORITY;
|
|
5
5
|
|
|
6
|
+
import android.util.Log;
|
|
6
7
|
import android.view.View;
|
|
7
8
|
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
8
10
|
import androidx.annotation.Nullable;
|
|
9
11
|
|
|
10
12
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
13
|
import com.facebook.react.bridge.ReadableMap;
|
|
12
14
|
import com.facebook.react.module.annotations.ReactModule;
|
|
15
|
+
import com.facebook.react.uimanager.LayoutShadowNode;
|
|
16
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
|
17
|
+
import com.facebook.react.uimanager.StateWrapper;
|
|
13
18
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
14
19
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
15
20
|
import com.facebook.react.uimanager.ViewManagerDelegate;
|
|
@@ -17,20 +22,25 @@ import com.facebook.react.viewmanagers.RNMapsMapViewManagerInterface;
|
|
|
17
22
|
import com.facebook.react.viewmanagers.RNMapsMapViewManagerDelegate;
|
|
18
23
|
import com.google.android.gms.maps.GoogleMap;
|
|
19
24
|
import com.google.android.gms.maps.GoogleMapOptions;
|
|
25
|
+
import com.google.android.gms.maps.MapsInitializer;
|
|
26
|
+
import com.google.android.gms.maps.model.CameraPosition;
|
|
20
27
|
import com.rnmaps.maps.MapView;
|
|
28
|
+
import com.rnmaps.maps.SizeReportingShadowNode;
|
|
21
29
|
|
|
22
30
|
import java.util.Map;
|
|
23
31
|
|
|
24
32
|
@ReactModule(name = MapViewManager.REACT_CLASS)
|
|
25
33
|
public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsMapViewManagerInterface<MapView> {
|
|
26
34
|
|
|
35
|
+
private static boolean rendererInitialized = false;
|
|
36
|
+
private final RNMapsMapViewManagerDelegate<MapView, MapViewManager> delegate =
|
|
37
|
+
new RNMapsMapViewManagerDelegate<>(this);
|
|
38
|
+
|
|
27
39
|
|
|
28
40
|
public MapViewManager(ReactApplicationContext context) {
|
|
29
41
|
super(context);
|
|
30
42
|
}
|
|
31
|
-
|
|
32
|
-
private final RNMapsMapViewManagerDelegate<MapView, MapViewManager> delegate =
|
|
33
|
-
new RNMapsMapViewManagerDelegate<>(this);
|
|
43
|
+
|
|
34
44
|
|
|
35
45
|
@Override
|
|
36
46
|
public ViewManagerDelegate<MapView> getDelegate() {
|
|
@@ -44,7 +54,88 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
44
54
|
|
|
45
55
|
@Override
|
|
46
56
|
public MapView createViewInstance(ThemedReactContext context) {
|
|
47
|
-
return new MapView(context,
|
|
57
|
+
return new MapView(context, new GoogleMapOptions());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Override
|
|
61
|
+
protected void setupViewRecycling() {
|
|
62
|
+
// override parent to block recycling / allow reliable GoogleMapsOptions passing
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
protected MapView createViewInstance(int reactTag, @NonNull ThemedReactContext reactContext, @Nullable ReactStylesDiffMap initialProps, @Nullable StateWrapper stateWrapper) {
|
|
67
|
+
MapView view = null;
|
|
68
|
+
GoogleMapOptions options = new GoogleMapOptions();
|
|
69
|
+
if (initialProps != null) {
|
|
70
|
+
setGoogleRenderer(null, initialProps.getString("googleRenderer"));
|
|
71
|
+
if (initialProps.hasKey("liteMode")) {
|
|
72
|
+
options.liteMode(initialProps.getBoolean("liteMode", false));
|
|
73
|
+
}
|
|
74
|
+
if (initialProps.hasKey("googleMapId")) {
|
|
75
|
+
String googleMapId = initialProps.getString("googleMapId");
|
|
76
|
+
options.mapId(googleMapId);
|
|
77
|
+
}
|
|
78
|
+
if (initialProps.getMap("initialCamera") != null) {
|
|
79
|
+
ReadableMap initialCamera = initialProps.getMap("initialCamera");
|
|
80
|
+
CameraPosition camera = MapView.cameraPositionFromMap(initialCamera);
|
|
81
|
+
if (camera != null) {
|
|
82
|
+
options.camera(camera);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (initialProps.hasKey("mapType")) {
|
|
86
|
+
if (initialProps.getString("mapType") != null) {
|
|
87
|
+
options.mapType(mapTypeFromStrValue(initialProps.getString("mapType")));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (initialProps.hasKey("minZoom")) {
|
|
91
|
+
if (initialProps.getInt("minZoom", 0) != 0) {
|
|
92
|
+
options.minZoomPreference(initialProps.getInt("minZoom", 0));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (initialProps.hasKey("maxZoom")) {
|
|
96
|
+
if (initialProps.getInt("maxZoom", 0) != 0) {
|
|
97
|
+
options.maxZoomPreference(initialProps.getInt("maxZoom", 0));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (initialProps.hasKey("pitchEnabled")) {
|
|
101
|
+
options.tiltGesturesEnabled(initialProps.getBoolean("pitchEnabled", true));
|
|
102
|
+
}
|
|
103
|
+
if (initialProps.hasKey("rotateEnabled")) {
|
|
104
|
+
options.rotateGesturesEnabled(initialProps.getBoolean("rotateEnabled", true));
|
|
105
|
+
}
|
|
106
|
+
if (initialProps.hasKey("scrollDuringRotateOrZoomEnabled")) {
|
|
107
|
+
options.scrollGesturesEnabledDuringRotateOrZoom(initialProps.getBoolean("scrollDuringRotateOrZoomEnabled", true));
|
|
108
|
+
}
|
|
109
|
+
if (initialProps.hasKey("scrollEnabled")) {
|
|
110
|
+
options.scrollGesturesEnabled(initialProps.getBoolean("scrollEnabled", true));
|
|
111
|
+
}
|
|
112
|
+
if (initialProps.hasKey("showsCompass")) {
|
|
113
|
+
options.compassEnabled(initialProps.getBoolean("showsCompass", true));
|
|
114
|
+
}
|
|
115
|
+
if (initialProps.hasKey("toolbarEnabled")) {
|
|
116
|
+
options.mapToolbarEnabled(initialProps.getBoolean("toolbarEnabled", true));
|
|
117
|
+
}
|
|
118
|
+
if (initialProps.hasKey("zoomControlEnabled")) {
|
|
119
|
+
options.zoomControlsEnabled(initialProps.getBoolean("zoomControlEnabled", true));
|
|
120
|
+
}
|
|
121
|
+
if (initialProps.hasKey("zoomEnabled")) {
|
|
122
|
+
options.zoomGesturesEnabled(initialProps.getBoolean("zoomEnabled", true));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
view = new MapView(reactContext, options);
|
|
127
|
+
view.setId(reactTag);
|
|
128
|
+
this.addEventEmitters(reactContext, view);
|
|
129
|
+
if (initialProps != null) {
|
|
130
|
+
this.updateProperties(view, initialProps);
|
|
131
|
+
}
|
|
132
|
+
if (stateWrapper != null) {
|
|
133
|
+
Object extraData = this.updateState(view, initialProps, stateWrapper);
|
|
134
|
+
if (extraData != null) {
|
|
135
|
+
this.updateExtraData(view, extraData);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return view;
|
|
48
139
|
}
|
|
49
140
|
|
|
50
141
|
|
|
@@ -56,6 +147,14 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
56
147
|
return MapView.getExportedCustomBubblingEventTypeConstants();
|
|
57
148
|
}
|
|
58
149
|
|
|
150
|
+
|
|
151
|
+
@Override
|
|
152
|
+
public LayoutShadowNode createShadowNodeInstance() {
|
|
153
|
+
// A custom shadow node is needed in order to pass back the width/height of the map to the
|
|
154
|
+
// view manager so that it can start applying camera moves with bounds.
|
|
155
|
+
return new SizeReportingShadowNode();
|
|
156
|
+
}
|
|
157
|
+
|
|
59
158
|
@Nullable
|
|
60
159
|
@Override
|
|
61
160
|
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
|
@@ -89,9 +188,13 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
89
188
|
|
|
90
189
|
@Override
|
|
91
190
|
public void setInitialCamera(MapView view, @Nullable ReadableMap value) {
|
|
92
|
-
|
|
191
|
+
CameraPosition camera = MapView.cameraPositionFromMap(value);
|
|
192
|
+
if (camera != null) {
|
|
193
|
+
view.setInitialCameraSet(true);
|
|
194
|
+
}
|
|
93
195
|
}
|
|
94
196
|
|
|
197
|
+
|
|
95
198
|
@Override
|
|
96
199
|
public void setInitialRegion(MapView view, @Nullable ReadableMap value) {
|
|
97
200
|
view.setInitialRegion(value);
|
|
@@ -114,11 +217,20 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
114
217
|
|
|
115
218
|
@Override
|
|
116
219
|
public void setGoogleMapId(MapView view, @Nullable String value) {
|
|
220
|
+
// do nothing (initialProp)
|
|
117
221
|
|
|
118
222
|
}
|
|
119
223
|
|
|
120
224
|
@Override
|
|
121
225
|
public void setGoogleRenderer(MapView view, @Nullable String value) {
|
|
226
|
+
if (!rendererInitialized) {
|
|
227
|
+
MapsInitializer.Renderer renderer = MapsInitializer.Renderer.LATEST;
|
|
228
|
+
if ("LEGACY".equals(value)) {
|
|
229
|
+
renderer = MapsInitializer.Renderer.LEGACY;
|
|
230
|
+
}
|
|
231
|
+
MapsInitializer.initialize(getReactApplicationContext(), renderer, r -> Log.d("AirMapRenderer", "Init with renderer: " + r));
|
|
232
|
+
rendererInitialized = true;
|
|
233
|
+
}
|
|
122
234
|
|
|
123
235
|
}
|
|
124
236
|
|
|
@@ -174,18 +286,26 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
174
286
|
|
|
175
287
|
@Override
|
|
176
288
|
public void setMapType(MapView view, @Nullable String value) {
|
|
289
|
+
view.setMapType(mapTypeFromStrValue(value));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private static int mapTypeFromStrValue(String value) {
|
|
293
|
+
int mapType;
|
|
177
294
|
//hybrid | none | satellite | standard | terrain
|
|
178
295
|
if ("hybrid".equals(value)) {
|
|
179
|
-
|
|
296
|
+
mapType = GoogleMap.MAP_TYPE_HYBRID;
|
|
180
297
|
} else if ("none".equals(value)) {
|
|
181
|
-
|
|
298
|
+
mapType = GoogleMap.MAP_TYPE_NONE;
|
|
182
299
|
} else if ("satellite".equals(value)) {
|
|
183
|
-
|
|
300
|
+
mapType = GoogleMap.MAP_TYPE_SATELLITE;
|
|
184
301
|
} else if ("standard".equals(value)) {
|
|
185
|
-
|
|
302
|
+
mapType = GoogleMap.MAP_TYPE_NORMAL;
|
|
186
303
|
} else if ("terrain".equals(value)) {
|
|
187
|
-
|
|
304
|
+
mapType = GoogleMap.MAP_TYPE_TERRAIN;
|
|
305
|
+
} else {
|
|
306
|
+
mapType = GoogleMap.MAP_TYPE_NORMAL;
|
|
188
307
|
}
|
|
308
|
+
return mapType;
|
|
189
309
|
}
|
|
190
310
|
|
|
191
311
|
@Override
|
|
@@ -210,7 +330,7 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
210
330
|
|
|
211
331
|
@Override
|
|
212
332
|
public void setMoveOnMarkerPress(MapView view, boolean value) {
|
|
213
|
-
|
|
333
|
+
view.setMoveOnMarkerPress(value);
|
|
214
334
|
}
|
|
215
335
|
|
|
216
336
|
@Override
|
|
@@ -220,7 +340,7 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
220
340
|
|
|
221
341
|
@Override
|
|
222
342
|
public void setPaddingAdjustmentBehavior(MapView view, @Nullable String value) {
|
|
223
|
-
|
|
343
|
+
// not supported
|
|
224
344
|
}
|
|
225
345
|
|
|
226
346
|
@Override
|
|
@@ -250,7 +370,7 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
250
370
|
|
|
251
371
|
@Override
|
|
252
372
|
public void setShowsBuildings(MapView view, boolean value) {
|
|
253
|
-
|
|
373
|
+
view.setShowBuildings(value);
|
|
254
374
|
}
|
|
255
375
|
|
|
256
376
|
@Override
|
|
@@ -295,7 +415,7 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
295
415
|
|
|
296
416
|
@Override
|
|
297
417
|
public void setUserInterfaceStyle(MapView view, @Nullable String value) {
|
|
298
|
-
//
|
|
418
|
+
// todo update google maps SDK and add support for MapColorScheme
|
|
299
419
|
}
|
|
300
420
|
|
|
301
421
|
@Override
|
|
@@ -372,4 +492,10 @@ public class MapViewManager extends ViewGroupManager<MapView> implements RNMapsM
|
|
|
372
492
|
public void fitToCoordinates(MapView view, String coordinatesJSON, String edgePaddingJSON, boolean animated) {
|
|
373
493
|
|
|
374
494
|
}
|
|
495
|
+
|
|
496
|
+
@Override
|
|
497
|
+
public void onDropViewInstance(MapView view) {
|
|
498
|
+
super.onDropViewInstance(view);
|
|
499
|
+
view.onDestroy();
|
|
500
|
+
}
|
|
375
501
|
}
|
|
@@ -43,7 +43,6 @@ import com.google.android.gms.maps.CameraUpdate;
|
|
|
43
43
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
|
44
44
|
import com.google.android.gms.maps.GoogleMap;
|
|
45
45
|
import com.google.android.gms.maps.GoogleMapOptions;
|
|
46
|
-
import com.google.android.gms.maps.MapsInitializer;
|
|
47
46
|
import com.google.android.gms.maps.OnMapReadyCallback;
|
|
48
47
|
import com.google.android.gms.maps.Projection;
|
|
49
48
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
@@ -185,7 +184,6 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
|
|
|
185
184
|
GoogleMapOptions googleMapOptions) {
|
|
186
185
|
super(context, googleMapOptions);
|
|
187
186
|
// todo add support for legacy renderer
|
|
188
|
-
MapsInitializer.initialize(context, MapsInitializer.Renderer.LATEST, renderer -> Log.d("AirMapRenderer", renderer.toString()));
|
|
189
187
|
this.context = context;
|
|
190
188
|
super.onCreate(null);
|
|
191
189
|
super.onResume();
|
|
@@ -634,6 +632,10 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
|
|
|
634
632
|
onDestroy();
|
|
635
633
|
}
|
|
636
634
|
|
|
635
|
+
public void setInitialCameraSet(boolean initialCameraSet){
|
|
636
|
+
this.initialCameraSet = initialCameraSet;
|
|
637
|
+
}
|
|
638
|
+
|
|
637
639
|
public void setInitialRegion(ReadableMap initialRegion) {
|
|
638
640
|
this.initialRegion = initialRegion;
|
|
639
641
|
// Theoretically onMapReady might be called before setInitialRegion
|
|
@@ -669,18 +671,23 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
|
|
|
669
671
|
}
|
|
670
672
|
this.setPoiClickEnabled(poiClickEnabled);
|
|
671
673
|
}
|
|
672
|
-
|
|
674
|
+
public static LatLngBounds latLngBoundsFromRegion(ReadableMap region){
|
|
675
|
+
if (region == null) return null;
|
|
676
|
+
|
|
677
|
+
double lng = region.getDouble("longitude");
|
|
678
|
+
double lat = region.getDouble("latitude");
|
|
679
|
+
double lngDelta = region.getDouble("longitudeDelta");
|
|
680
|
+
double latDelta = region.getDouble("latitudeDelta");
|
|
681
|
+
return new LatLngBounds(
|
|
682
|
+
new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
|
|
683
|
+
new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
|
|
684
|
+
);
|
|
685
|
+
}
|
|
673
686
|
private void moveToRegion(ReadableMap region) {
|
|
674
|
-
|
|
675
|
-
|
|
687
|
+
LatLngBounds bounds = latLngBoundsFromRegion(region);
|
|
688
|
+
if (bounds == null) return;
|
|
676
689
|
double lng = region.getDouble("longitude");
|
|
677
690
|
double lat = region.getDouble("latitude");
|
|
678
|
-
double lngDelta = region.getDouble("longitudeDelta");
|
|
679
|
-
double latDelta = region.getDouble("latitudeDelta");
|
|
680
|
-
LatLngBounds bounds = new LatLngBounds(
|
|
681
|
-
new LatLng(lat - latDelta / 2, lng - lngDelta / 2), // southwest
|
|
682
|
-
new LatLng(lat + latDelta / 2, lng + lngDelta / 2) // northeast
|
|
683
|
-
);
|
|
684
691
|
if (super.getHeight() <= 0 || super.getWidth() <= 0) {
|
|
685
692
|
// in this case, our map has not been laid out yet, so we save the bounds in a local
|
|
686
693
|
// variable, and make a guess of zoomLevel 10. Not to worry, though: as soon as layout
|
|
@@ -770,18 +777,24 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
|
|
|
770
777
|
}
|
|
771
778
|
|
|
772
779
|
public void setShowsMyLocationButton(boolean showMyLocationButton) {
|
|
773
|
-
if (
|
|
774
|
-
|
|
780
|
+
if (map != null) {
|
|
781
|
+
if (hasPermissions() || !showMyLocationButton) {
|
|
782
|
+
map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);
|
|
783
|
+
}
|
|
775
784
|
}
|
|
776
785
|
}
|
|
777
786
|
|
|
778
787
|
public void setToolbarEnabled(boolean toolbarEnabled) {
|
|
779
|
-
if (
|
|
780
|
-
|
|
788
|
+
if (map != null) {
|
|
789
|
+
if (hasPermissions() || !toolbarEnabled) {
|
|
790
|
+
map.getUiSettings().setMapToolbarEnabled(toolbarEnabled);
|
|
791
|
+
}
|
|
781
792
|
}
|
|
782
793
|
}
|
|
783
794
|
public void setMapType(int mapType){
|
|
784
|
-
map
|
|
795
|
+
if (map != null) {
|
|
796
|
+
map.setMapType(mapType);
|
|
797
|
+
}
|
|
785
798
|
}
|
|
786
799
|
|
|
787
800
|
public void setCacheEnabled(boolean cacheEnabled) {
|
|
@@ -791,7 +804,9 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
|
|
|
791
804
|
|
|
792
805
|
public void setPoiClickEnabled(boolean poiClickEnabled) {
|
|
793
806
|
this.poiClickEnabled = poiClickEnabled;
|
|
794
|
-
map
|
|
807
|
+
if (map != null) {
|
|
808
|
+
map.setOnPoiClickListener(poiClickEnabled ? this : null);
|
|
809
|
+
}
|
|
795
810
|
}
|
|
796
811
|
|
|
797
812
|
public void setLoadingEnabled(boolean loadingEnabled) {
|
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.
|
|
8
|
+
"version": "1.21.0-alpha.56",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"lint": "eslint . --max-warnings 0",
|