react-native-maps 1.15.4 → 1.15.5

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.
@@ -19,9 +19,6 @@ import com.facebook.react.bridge.ReadableMap;
19
19
  import com.facebook.react.bridge.WritableMap;
20
20
  import com.facebook.react.bridge.WritableNativeMap;
21
21
  import com.facebook.react.module.annotations.ReactModule;
22
- import com.facebook.react.uimanager.NativeViewHierarchyManager;
23
- import com.facebook.react.uimanager.UIBlock;
24
- import com.facebook.react.uimanager.UIManagerModule;
25
22
  import com.google.android.gms.maps.GoogleMap;
26
23
  import com.google.android.gms.maps.model.CameraPosition;
27
24
  import com.google.android.gms.maps.model.LatLng;
@@ -89,19 +86,7 @@ public class MapModule extends ReactContextBaseJavaModule {
89
86
  options.hasKey("height") ? (int) (displayMetrics.density * options.getDouble("height")) : 0;
90
87
  final String result = options.hasKey("result") ? options.getString("result") : "file";
91
88
 
92
- // Add UI-block so we can get a valid reference to the map-view
93
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
94
- uiManager.addUIBlock(new UIBlock() {
95
- public void execute(NativeViewHierarchyManager nvhm) {
96
- MapView view = (MapView) nvhm.resolveView(tag);
97
- if (view == null) {
98
- promise.reject("AirMapView not found");
99
- return;
100
- }
101
- if (view.map == null) {
102
- promise.reject("AirMapView.map is not valid");
103
- return;
104
- }
89
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
105
90
  view.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
106
91
  public void onSnapshotReady(@Nullable Bitmap snapshot) {
107
92
 
@@ -141,30 +126,20 @@ public class MapModule extends ReactContextBaseJavaModule {
141
126
  }
142
127
  }
143
128
  });
144
- }
145
- });
129
+
130
+ return null;
131
+ });
132
+
133
+ // Add UI-block so we can get a valid reference to the map-view
134
+
135
+ uiBlock.addToUIManager();
146
136
  }
147
137
 
148
138
  @ReactMethod
149
139
  public void getCamera(final int tag, final Promise promise) {
150
140
  final ReactApplicationContext context = getReactApplicationContext();
151
141
 
152
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
153
- uiManager.addUIBlock(new UIBlock()
154
- {
155
- @Override
156
- public void execute(NativeViewHierarchyManager nvhm)
157
- {
158
- MapView view = (MapView) nvhm.resolveView(tag);
159
- if (view == null) {
160
- promise.reject("AirMapView not found");
161
- return;
162
- }
163
- if (view.map == null) {
164
- promise.reject("AirMapView.map is not valid");
165
- return;
166
- }
167
-
142
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
168
143
  CameraPosition position = view.map.getCameraPosition();
169
144
 
170
145
  WritableMap centerJson = new WritableNativeMap();
@@ -178,34 +153,23 @@ public class MapModule extends ReactContextBaseJavaModule {
178
153
  cameraJson.putDouble("pitch", (double)position.tilt);
179
154
 
180
155
  promise.resolve(cameraJson);
181
- }
156
+
157
+ return null;
182
158
  });
159
+
160
+ uiBlock.addToUIManager();
183
161
  }
184
162
 
185
163
  @ReactMethod
186
164
  public void getAddressFromCoordinates(final int tag, final ReadableMap coordinate, final Promise promise) {
187
165
  final ReactApplicationContext context = getReactApplicationContext();
188
166
 
189
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
190
- uiManager.addUIBlock(new UIBlock()
191
- {
192
- @Override
193
- public void execute(NativeViewHierarchyManager nvhm)
194
- {
195
- MapView view = (MapView) nvhm.resolveView(tag);
196
- if (view == null) {
197
- promise.reject("AirMapView not found");
198
- return;
199
- }
200
- if (view.map == null) {
201
- promise.reject("AirMapView.map is not valid");
202
- return;
203
- }
167
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, mapView -> {
204
168
  if (coordinate == null ||
205
169
  !coordinate.hasKey("latitude") ||
206
170
  !coordinate.hasKey("longitude")) {
207
171
  promise.reject("Invalid coordinate format");
208
- return;
172
+ return null;
209
173
  }
210
174
  Geocoder geocoder = new Geocoder(context);
211
175
  try {
@@ -213,7 +177,7 @@ public class MapModule extends ReactContextBaseJavaModule {
213
177
  geocoder.getFromLocation(coordinate.getDouble("latitude"),coordinate.getDouble("longitude"),1);
214
178
  if (list.isEmpty()) {
215
179
  promise.reject("Can not get address location");
216
- return;
180
+ return null;
217
181
  }
218
182
  Address address = list.get(0);
219
183
 
@@ -233,8 +197,11 @@ public class MapModule extends ReactContextBaseJavaModule {
233
197
  } catch (IOException e) {
234
198
  promise.reject("Can not get address location");
235
199
  }
236
- }
200
+
201
+ return null;
237
202
  });
203
+
204
+ uiBlock.addToUIManager();
238
205
  }
239
206
 
240
207
  @ReactMethod
@@ -247,22 +214,7 @@ public class MapModule extends ReactContextBaseJavaModule {
247
214
  coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
248
215
  );
249
216
 
250
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
251
- uiManager.addUIBlock(new UIBlock()
252
- {
253
- @Override
254
- public void execute(NativeViewHierarchyManager nvhm)
255
- {
256
- MapView view = (MapView) nvhm.resolveView(tag);
257
- if (view == null) {
258
- promise.reject("AirMapView not found");
259
- return;
260
- }
261
- if (view.map == null) {
262
- promise.reject("AirMapView.map is not valid");
263
- return;
264
- }
265
-
217
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
266
218
  Point pt = view.map.getProjection().toScreenLocation(coord);
267
219
 
268
220
  WritableMap ptJson = new WritableNativeMap();
@@ -270,8 +222,11 @@ public class MapModule extends ReactContextBaseJavaModule {
270
222
  ptJson.putDouble("y", (double)pt.y / density);
271
223
 
272
224
  promise.resolve(ptJson);
273
- }
225
+
226
+ return null;
274
227
  });
228
+
229
+ uiBlock.addToUIManager();
275
230
  }
276
231
 
277
232
  @ReactMethod
@@ -284,24 +239,7 @@ public class MapModule extends ReactContextBaseJavaModule {
284
239
  point.hasKey("y") ? (int)(point.getDouble("y") * density) : 0
285
240
  );
286
241
 
287
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
288
- uiManager.addUIBlock(new UIBlock()
289
- {
290
- @Override
291
- public void execute(NativeViewHierarchyManager nvhm)
292
- {
293
- MapView view = (MapView) nvhm.resolveView(tag);
294
- if (view == null)
295
- {
296
- promise.reject("AirMapView not found");
297
- return;
298
- }
299
- if (view.map == null)
300
- {
301
- promise.reject("AirMapView.map is not valid");
302
- return;
303
- }
304
-
242
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
305
243
  LatLng coord = view.map.getProjection().fromScreenLocation(pt);
306
244
 
307
245
  WritableMap coordJson = new WritableNativeMap();
@@ -309,30 +247,18 @@ public class MapModule extends ReactContextBaseJavaModule {
309
247
  coordJson.putDouble("longitude", coord.longitude);
310
248
 
311
249
  promise.resolve(coordJson);
312
- }
250
+
251
+ return null;
313
252
  });
253
+
254
+ uiBlock.addToUIManager();
314
255
  }
315
256
 
316
257
  @ReactMethod
317
258
  public void getMapBoundaries(final int tag, final Promise promise) {
318
259
  final ReactApplicationContext context = getReactApplicationContext();
319
260
 
320
- UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
321
- uiManager.addUIBlock(new UIBlock()
322
- {
323
- @Override
324
- public void execute(NativeViewHierarchyManager nvhm)
325
- {
326
- MapView view = (MapView) nvhm.resolveView(tag);
327
- if (view == null) {
328
- promise.reject("AirMapView not found");
329
- return;
330
- }
331
- if (view.map == null) {
332
- promise.reject("AirMapView.map is not valid");
333
- return;
334
- }
335
-
261
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
336
262
  double[][] boundaries = view.getMapBoundaries();
337
263
 
338
264
  WritableMap coordinates = new WritableNativeMap();
@@ -348,7 +274,10 @@ public class MapModule extends ReactContextBaseJavaModule {
348
274
  coordinates.putMap("southWest", southWestHash);
349
275
 
350
276
  promise.resolve(coordinates);
351
- }
277
+
278
+ return null;
352
279
  });
280
+
281
+ uiBlock.addToUIManager();
353
282
  }
354
283
  }
@@ -0,0 +1,64 @@
1
+ package com.rnmaps.maps;
2
+
3
+ import com.facebook.react.bridge.Promise;
4
+ import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.bridge.UIManager;
6
+ import com.facebook.react.fabric.FabricUIManager;
7
+ import com.facebook.react.fabric.interop.UIBlockViewResolver;
8
+ import com.facebook.react.uimanager.common.UIManagerType;
9
+ import com.facebook.react.uimanager.NativeViewHierarchyManager;
10
+ import com.facebook.react.uimanager.UIBlock;
11
+ import com.facebook.react.uimanager.UIManagerHelper;
12
+ import com.facebook.react.uimanager.UIManagerModule;
13
+
14
+ import java.util.function.Function;
15
+
16
+ public class MapUIBlock implements UIBlockInterface {
17
+ private int tag;
18
+ private Promise promise;
19
+ private ReactApplicationContext context;
20
+ private Function<MapView, Void> mapOperation;
21
+
22
+ public MapUIBlock(int tag, Promise promise, ReactApplicationContext context, Function<MapView, Void> mapOperation) {
23
+ this.tag = tag;
24
+ this.promise = promise;
25
+ this.context = context;
26
+ this.mapOperation = mapOperation;
27
+ }
28
+
29
+ @Override
30
+ public void execute(NativeViewHierarchyManager nvhm) {
31
+ executeImpl(nvhm, null);
32
+ }
33
+
34
+ @Override
35
+ public void execute(UIBlockViewResolver uiBlockViewResolver) {
36
+ executeImpl(null, uiBlockViewResolver);
37
+ }
38
+
39
+ private void executeImpl(NativeViewHierarchyManager nvhm, UIBlockViewResolver uiBlockViewResolver) {
40
+ MapView view = uiBlockViewResolver != null ? (MapView) uiBlockViewResolver.resolveView(tag) : (MapView) nvhm.resolveView(tag);
41
+ if (view == null) {
42
+ promise.reject("AirMapView not found");
43
+ return;
44
+ }
45
+ if (view.map == null) {
46
+ promise.reject("AirMapView.map is not valid");
47
+ return;
48
+ }
49
+
50
+ mapOperation.apply(view);
51
+ }
52
+
53
+ public void addToUIManager() {
54
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
55
+ UIManager uiManager = UIManagerHelper.getUIManager(context, UIManagerType.FABRIC);
56
+ ((FabricUIManager) uiManager).addUIBlock(this);
57
+ } else {
58
+ UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
59
+ uiManager.addUIBlock(this);
60
+ }
61
+ }
62
+ }
63
+
64
+ interface UIBlockInterface extends UIBlock, com.facebook.react.fabric.interop.UIBlock {}
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.15.4",
8
+ "version": "1.15.5",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",