react-native-maps 1.21.0-alpha.66 → 1.21.0-alpha.68

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.
@@ -20,7 +20,6 @@ import java.util.Map;
20
20
  @ReactModule(name = CalloutManager.REACT_CLASS)
21
21
  public class CalloutManager extends ViewGroupManager<MapCallout> implements RNMapsCalloutManagerInterface<MapCallout> {
22
22
 
23
-
24
23
  public CalloutManager(ReactApplicationContext context){
25
24
  super(context);
26
25
  }
@@ -75,15 +74,4 @@ public class CalloutManager extends ViewGroupManager<MapCallout> implements RNMa
75
74
  return new SizeReportingShadowNode();
76
75
  }
77
76
 
78
- @Override
79
- public void updateExtraData(MapCallout view, Object extraData) {
80
- // This method is called from the shadow node with the width/height of the rendered
81
- // marker view.
82
- //noinspection unchecked
83
- Map<String, Float> data = (Map<String, Float>) extraData;
84
- float width = data.get("width");
85
- float height = data.get("height");
86
- view.width = (int) width;
87
- view.height = (int) height;
88
- }
89
77
  }
@@ -1,5 +1,18 @@
1
1
  package com.rnmaps.fabric;
2
2
 
3
+ import static com.rnmaps.maps.MapModule.SNAPSHOT_FORMAT_JPG;
4
+ import static com.rnmaps.maps.MapModule.SNAPSHOT_FORMAT_PNG;
5
+ import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_BASE64;
6
+ import static com.rnmaps.maps.MapModule.SNAPSHOT_RESULT_FILE;
7
+ import static com.rnmaps.maps.MapModule.closeQuietly;
8
+
9
+ import android.graphics.Bitmap;
10
+ import android.net.Uri;
11
+ import android.util.Base64;
12
+ import android.util.DisplayMetrics;
13
+
14
+ import androidx.annotation.Nullable;
15
+
3
16
  import com.facebook.fbreact.specs.NativeAirMapsModuleSpec;
4
17
  import com.facebook.react.bridge.Arguments;
5
18
  import com.facebook.react.bridge.Promise;
@@ -8,9 +21,18 @@ import com.facebook.react.bridge.ReadableMap;
8
21
  import com.facebook.react.bridge.UIManager;
9
22
  import com.facebook.react.bridge.WritableMap;
10
23
  import com.facebook.react.uimanager.UIManagerHelper;
24
+ import com.google.android.gms.maps.GoogleMap;
11
25
  import com.google.android.gms.maps.model.CameraPosition;
26
+ import com.rnmaps.maps.MapUIBlock;
12
27
  import com.rnmaps.maps.MapView;
13
28
 
29
+ import org.json.JSONException;
30
+ import org.json.JSONObject;
31
+
32
+ import java.io.ByteArrayOutputStream;
33
+ import java.io.File;
34
+ import java.io.FileOutputStream;
35
+
14
36
  public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
15
37
  public NativeAirMapsModule(ReactApplicationContext reactContext) {
16
38
  super(reactContext);
@@ -23,23 +45,23 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
23
45
 
24
46
  @Override
25
47
  public void getCamera(double tag, Promise promise) {
26
- UIManager uiManager = UIManagerHelper.getUIManagerForReactTag(getReactApplicationContext(), (int) tag);
27
- getReactApplicationContext().runOnUiQueueThread(new Runnable() {
28
- @Override
29
- public void run() {
30
- MapView view = (MapView) uiManager.resolveView((int) tag);
31
- CameraPosition position = view.map.getCameraPosition();
32
- WritableMap map = Arguments.createMap();
33
- WritableMap center = Arguments.createMap();
34
- center.putDouble("latitude", position.target.latitude);
35
- center.putDouble("longitude", position.target.longitude);
36
- map.putMap("center", center);
37
- map.putDouble("heading", position.bearing);
38
- map.putDouble("pitch", position.tilt);
39
- map.putDouble("zoom", position.zoom);
40
- promise.resolve(map);
41
- }
42
- });
48
+ UIManager uiManager = UIManagerHelper.getUIManagerForReactTag(getReactApplicationContext(), (int) tag);
49
+ getReactApplicationContext().runOnUiQueueThread(new Runnable() {
50
+ @Override
51
+ public void run() {
52
+ MapView view = (MapView) uiManager.resolveView((int) tag);
53
+ CameraPosition position = view.map.getCameraPosition();
54
+ WritableMap map = Arguments.createMap();
55
+ WritableMap center = Arguments.createMap();
56
+ center.putDouble("latitude", position.target.latitude);
57
+ center.putDouble("longitude", position.target.longitude);
58
+ map.putMap("center", center);
59
+ map.putDouble("heading", position.bearing);
60
+ map.putDouble("pitch", position.tilt);
61
+ map.putDouble("zoom", position.zoom);
62
+ promise.resolve(map);
63
+ }
64
+ });
43
65
  }
44
66
 
45
67
  @Override
@@ -54,7 +76,74 @@ public class NativeAirMapsModule extends NativeAirMapsModuleSpec {
54
76
 
55
77
  @Override
56
78
  public void takeSnapshot(double tag, String config, Promise promise) {
57
-
79
+ WritableMap options = null;
80
+ try {
81
+ if (config != null) {
82
+ JSONObject jsonObject = new JSONObject(config);
83
+ options = JSONUtil.convertJsonToWritable(jsonObject);
84
+ WritableMap finalOptions = options;
85
+
86
+ final ReactApplicationContext context = getReactApplicationContext();
87
+ final String format = finalOptions.hasKey("format") ? finalOptions.getString("format") : "png";
88
+ final Bitmap.CompressFormat compressFormat =
89
+ format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
90
+ format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
91
+ final double quality = finalOptions.hasKey("quality") ? finalOptions.getDouble("quality") : 1.0;
92
+ final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
93
+ final Integer width =
94
+ finalOptions.hasKey("width") ? (int) (displayMetrics.density * finalOptions.getDouble("width")) : 0;
95
+ final Integer height =
96
+ finalOptions.hasKey("height") ? (int) (displayMetrics.density * finalOptions.getDouble("height")) : 0;
97
+ final String result = finalOptions.hasKey("result") ? finalOptions.getString("result") : "file";
98
+
99
+ UIManager uiManager = UIManagerHelper.getUIManagerForReactTag(getReactApplicationContext(), (int) tag);
100
+ getReactApplicationContext().runOnUiQueueThread(new Runnable() {
101
+ @Override
102
+ public void run() {
103
+ MapView view = (MapView) uiManager.resolveView((int) tag);
104
+ view.map.snapshot(snapshot -> {
105
+
106
+ // Convert image to requested width/height if necessary
107
+ if (snapshot == null) {
108
+ promise.reject("Failed to generate bitmap, snapshot = null");
109
+ return;
110
+ }
111
+ if ((width != 0) && (height != 0) &&
112
+ (width != snapshot.getWidth() || height != snapshot.getHeight())) {
113
+ snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
114
+ }
115
+ // Save the snapshot to disk
116
+ if (result.equals(SNAPSHOT_RESULT_FILE)) {
117
+ File tempFile;
118
+ FileOutputStream outputStream;
119
+ try {
120
+ tempFile =
121
+ File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
122
+ outputStream = new FileOutputStream(tempFile);
123
+ } catch (Exception e) {
124
+ promise.reject(e);
125
+ return;
126
+ }
127
+ snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
128
+ closeQuietly(outputStream);
129
+ String uri = Uri.fromFile(tempFile).toString();
130
+ promise.resolve(uri);
131
+ } else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
132
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
133
+ snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
134
+ closeQuietly(outputStream);
135
+ byte[] bytes = outputStream.toByteArray();
136
+ String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
137
+ promise.resolve(data);
138
+ }
139
+ });
140
+ }
141
+ });
142
+ }
143
+ } catch (JSONException e) {
144
+ promise.reject("Failed to parse config ", config);
145
+
146
+ }
58
147
  }
59
148
 
60
149
  @Override
@@ -4,14 +4,6 @@ import android.content.Context;
4
4
 
5
5
  import com.facebook.react.common.MapBuilder;
6
6
  import com.facebook.react.views.view.ReactViewGroup;
7
- import com.rnmaps.fabric.event.OnLongPressEvent;
8
- import com.rnmaps.fabric.event.OnMarkerDeselectEvent;
9
- import com.rnmaps.fabric.event.OnMarkerDragEndEvent;
10
- import com.rnmaps.fabric.event.OnMarkerDragEvent;
11
- import com.rnmaps.fabric.event.OnMarkerDragStartEvent;
12
- import com.rnmaps.fabric.event.OnMarkerPressEvent;
13
- import com.rnmaps.fabric.event.OnMarkerSelectEvent;
14
- import com.rnmaps.fabric.event.OnPoiClickEvent;
15
7
  import com.rnmaps.fabric.event.OnPressEvent;
16
8
 
17
9
  import java.util.Map;
@@ -33,6 +25,13 @@ public class MapCallout extends ReactViewGroup {
33
25
  return this.tooltip;
34
26
  }
35
27
 
28
+ @Override
29
+ protected void onLayout(boolean changed,
30
+ int left, int top, int right, int bottom){
31
+ width = right - left;
32
+ height = bottom - top;
33
+ }
34
+
36
35
 
37
36
  public static Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
38
37
  MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
@@ -35,249 +35,249 @@ import java.util.Map;
35
35
  @ReactModule(name = MapModule.NAME)
36
36
  public class MapModule extends ReactContextBaseJavaModule {
37
37
 
38
- public static final String NAME = "AirMapModule";
39
- private static final String SNAPSHOT_RESULT_FILE = "file";
40
- private static final String SNAPSHOT_RESULT_BASE64 = "base64";
41
- private static final String SNAPSHOT_FORMAT_PNG = "png";
42
- private static final String SNAPSHOT_FORMAT_JPG = "jpg";
43
-
44
- public MapModule(ReactApplicationContext reactContext) {
45
- super(reactContext);
46
- }
47
-
48
- @Override
49
- public String getName() {
50
- return NAME;
51
- }
52
-
53
- @Override
54
- public Map<String, Object> getConstants() {
55
- final Map<String, Object> constants = new HashMap<>();
56
- constants.put("legalNotice", "This license information is displayed in Settings > Google > Open Source on any device running Google Play services.");
57
- return constants;
58
- }
59
-
60
- public Activity getActivity() {
61
- return getCurrentActivity();
62
- }
63
-
64
- public static void closeQuietly(Closeable closeable) {
65
- if (closeable == null) return;
66
- try {
67
- closeable.close();
68
- } catch (IOException ignored) {
38
+ public static final String NAME = "AirMapModule";
39
+ public static final String SNAPSHOT_RESULT_FILE = "file";
40
+ public static final String SNAPSHOT_RESULT_BASE64 = "base64";
41
+ public static final String SNAPSHOT_FORMAT_PNG = "png";
42
+ public static final String SNAPSHOT_FORMAT_JPG = "jpg";
43
+
44
+ public MapModule(ReactApplicationContext reactContext) {
45
+ super(reactContext);
69
46
  }
70
- }
71
-
72
- @ReactMethod
73
- public void takeSnapshot(final int tag, final ReadableMap options, final Promise promise) {
74
-
75
- // Parse and verity options
76
- final ReactApplicationContext context = getReactApplicationContext();
77
- final String format = options.hasKey("format") ? options.getString("format") : "png";
78
- final Bitmap.CompressFormat compressFormat =
79
- format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
80
- format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
81
- final double quality = options.hasKey("quality") ? options.getDouble("quality") : 1.0;
82
- final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
83
- final Integer width =
84
- options.hasKey("width") ? (int) (displayMetrics.density * options.getDouble("width")) : 0;
85
- final Integer height =
86
- options.hasKey("height") ? (int) (displayMetrics.density * options.getDouble("height")) : 0;
87
- final String result = options.hasKey("result") ? options.getString("result") : "file";
88
-
89
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
90
- view.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
91
- public void onSnapshotReady(@Nullable Bitmap snapshot) {
92
-
93
- // Convert image to requested width/height if necessary
94
- if (snapshot == null) {
95
- promise.reject("Failed to generate bitmap, snapshot = null");
96
- return;
97
- }
98
- if ((width != 0) && (height != 0) &&
99
- (width != snapshot.getWidth() || height != snapshot.getHeight())) {
100
- snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
101
- }
102
47
 
103
- // Save the snapshot to disk
104
- if (result.equals(SNAPSHOT_RESULT_FILE)) {
105
- File tempFile;
106
- FileOutputStream outputStream;
107
- try {
108
- tempFile =
109
- File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
110
- outputStream = new FileOutputStream(tempFile);
111
- } catch (Exception e) {
112
- promise.reject(e);
113
- return;
114
- }
115
- snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
116
- closeQuietly(outputStream);
117
- String uri = Uri.fromFile(tempFile).toString();
118
- promise.resolve(uri);
119
- } else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
120
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
121
- snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
122
- closeQuietly(outputStream);
123
- byte[] bytes = outputStream.toByteArray();
124
- String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
125
- promise.resolve(data);
126
- }
127
- }
128
- });
48
+ @Override
49
+ public String getName() {
50
+ return NAME;
51
+ }
129
52
 
130
- return null;
131
- });
53
+ @Override
54
+ public Map<String, Object> getConstants() {
55
+ final Map<String, Object> constants = new HashMap<>();
56
+ constants.put("legalNotice", "This license information is displayed in Settings > Google > Open Source on any device running Google Play services.");
57
+ return constants;
58
+ }
59
+
60
+ public Activity getActivity() {
61
+ return getCurrentActivity();
62
+ }
132
63
 
133
- // Add UI-block so we can get a valid reference to the map-view
64
+ public static void closeQuietly(Closeable closeable) {
65
+ if (closeable == null) return;
66
+ try {
67
+ closeable.close();
68
+ } catch (IOException ignored) {
69
+ }
70
+ }
134
71
 
135
- uiBlock.addToUIManager();
136
- }
72
+ @ReactMethod
73
+ public void takeSnapshot(final int tag, final ReadableMap options, final Promise promise) {
74
+
75
+ // Parse and verity options
76
+ final ReactApplicationContext context = getReactApplicationContext();
77
+ final String format = options.hasKey("format") ? options.getString("format") : "png";
78
+ final Bitmap.CompressFormat compressFormat =
79
+ format.equals(SNAPSHOT_FORMAT_PNG) ? Bitmap.CompressFormat.PNG :
80
+ format.equals(SNAPSHOT_FORMAT_JPG) ? Bitmap.CompressFormat.JPEG : null;
81
+ final double quality = options.hasKey("quality") ? options.getDouble("quality") : 1.0;
82
+ final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
83
+ final Integer width =
84
+ options.hasKey("width") ? (int) (displayMetrics.density * options.getDouble("width")) : 0;
85
+ final Integer height =
86
+ options.hasKey("height") ? (int) (displayMetrics.density * options.getDouble("height")) : 0;
87
+ final String result = options.hasKey("result") ? options.getString("result") : "file";
88
+
89
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
90
+ view.map.snapshot(new GoogleMap.SnapshotReadyCallback() {
91
+ public void onSnapshotReady(@Nullable Bitmap snapshot) {
92
+
93
+ // Convert image to requested width/height if necessary
94
+ if (snapshot == null) {
95
+ promise.reject("Failed to generate bitmap, snapshot = null");
96
+ return;
97
+ }
98
+ if ((width != 0) && (height != 0) &&
99
+ (width != snapshot.getWidth() || height != snapshot.getHeight())) {
100
+ snapshot = Bitmap.createScaledBitmap(snapshot, width, height, true);
101
+ }
102
+
103
+ // Save the snapshot to disk
104
+ if (result.equals(SNAPSHOT_RESULT_FILE)) {
105
+ File tempFile;
106
+ FileOutputStream outputStream;
107
+ try {
108
+ tempFile =
109
+ File.createTempFile("AirMapSnapshot", "." + format, context.getCacheDir());
110
+ outputStream = new FileOutputStream(tempFile);
111
+ } catch (Exception e) {
112
+ promise.reject(e);
113
+ return;
114
+ }
115
+ snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
116
+ closeQuietly(outputStream);
117
+ String uri = Uri.fromFile(tempFile).toString();
118
+ promise.resolve(uri);
119
+ } else if (result.equals(SNAPSHOT_RESULT_BASE64)) {
120
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
121
+ snapshot.compress(compressFormat, (int) (100.0 * quality), outputStream);
122
+ closeQuietly(outputStream);
123
+ byte[] bytes = outputStream.toByteArray();
124
+ String data = Base64.encodeToString(bytes, Base64.NO_WRAP);
125
+ promise.resolve(data);
126
+ }
127
+ }
128
+ });
137
129
 
138
- @ReactMethod
139
- public void getCamera(final int tag, final Promise promise) {
140
- final ReactApplicationContext context = getReactApplicationContext();
130
+ return null;
131
+ });
141
132
 
142
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
143
- CameraPosition position = view.map.getCameraPosition();
133
+ // Add UI-block so we can get a valid reference to the map-view
144
134
 
145
- WritableMap centerJson = new WritableNativeMap();
146
- centerJson.putDouble("latitude", position.target.latitude);
147
- centerJson.putDouble("longitude", position.target.longitude);
135
+ uiBlock.addToUIManager();
136
+ }
148
137
 
149
- WritableMap cameraJson = new WritableNativeMap();
150
- cameraJson.putMap("center", centerJson);
151
- cameraJson.putDouble("heading", (double)position.bearing);
152
- cameraJson.putDouble("zoom", (double)position.zoom);
153
- cameraJson.putDouble("pitch", (double)position.tilt);
138
+ @ReactMethod
139
+ public void getCamera(final int tag, final Promise promise) {
140
+ final ReactApplicationContext context = getReactApplicationContext();
154
141
 
155
- promise.resolve(cameraJson);
142
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
143
+ CameraPosition position = view.map.getCameraPosition();
156
144
 
157
- return null;
158
- });
145
+ WritableMap centerJson = new WritableNativeMap();
146
+ centerJson.putDouble("latitude", position.target.latitude);
147
+ centerJson.putDouble("longitude", position.target.longitude);
159
148
 
160
- uiBlock.addToUIManager();
161
- }
149
+ WritableMap cameraJson = new WritableNativeMap();
150
+ cameraJson.putMap("center", centerJson);
151
+ cameraJson.putDouble("heading", (double) position.bearing);
152
+ cameraJson.putDouble("zoom", (double) position.zoom);
153
+ cameraJson.putDouble("pitch", (double) position.tilt);
162
154
 
163
- @ReactMethod
164
- public void getAddressFromCoordinates(final int tag, final ReadableMap coordinate, final Promise promise) {
165
- final ReactApplicationContext context = getReactApplicationContext();
155
+ promise.resolve(cameraJson);
166
156
 
167
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, mapView -> {
168
- if (coordinate == null ||
169
- !coordinate.hasKey("latitude") ||
170
- !coordinate.hasKey("longitude")) {
171
- promise.reject("Invalid coordinate format");
172
- return null;
173
- }
174
- Geocoder geocoder = new Geocoder(context);
175
- try {
176
- List<Address> list =
177
- geocoder.getFromLocation(coordinate.getDouble("latitude"),coordinate.getDouble("longitude"),1);
178
- if (list.isEmpty()) {
179
- promise.reject("Can not get address location");
180
157
  return null;
181
- }
182
- Address address = list.get(0);
183
-
184
- WritableMap addressJson = new WritableNativeMap();
185
- addressJson.putString("name", address.getFeatureName());
186
- addressJson.putString("locality", address.getLocality());
187
- addressJson.putString("thoroughfare", address.getThoroughfare());
188
- addressJson.putString("subThoroughfare", address.getSubThoroughfare());
189
- addressJson.putString("subLocality", address.getSubLocality());
190
- addressJson.putString("administrativeArea", address.getAdminArea());
191
- addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
192
- addressJson.putString("postalCode", address.getPostalCode());
193
- addressJson.putString("countryCode", address.getCountryCode());
194
- addressJson.putString("country", address.getCountryName());
195
-
196
- promise.resolve(addressJson);
197
- } catch (IOException e) {
198
- promise.reject("Can not get address location");
199
- }
158
+ });
200
159
 
201
- return null;
202
- });
160
+ uiBlock.addToUIManager();
161
+ }
162
+
163
+ @ReactMethod
164
+ public void getAddressFromCoordinates(final int tag, final ReadableMap coordinate, final Promise promise) {
165
+ final ReactApplicationContext context = getReactApplicationContext();
166
+
167
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, mapView -> {
168
+ if (coordinate == null ||
169
+ !coordinate.hasKey("latitude") ||
170
+ !coordinate.hasKey("longitude")) {
171
+ promise.reject("Invalid coordinate format");
172
+ return null;
173
+ }
174
+ Geocoder geocoder = new Geocoder(context);
175
+ try {
176
+ List<Address> list =
177
+ geocoder.getFromLocation(coordinate.getDouble("latitude"), coordinate.getDouble("longitude"), 1);
178
+ if (list.isEmpty()) {
179
+ promise.reject("Can not get address location");
180
+ return null;
181
+ }
182
+ Address address = list.get(0);
183
+
184
+ WritableMap addressJson = new WritableNativeMap();
185
+ addressJson.putString("name", address.getFeatureName());
186
+ addressJson.putString("locality", address.getLocality());
187
+ addressJson.putString("thoroughfare", address.getThoroughfare());
188
+ addressJson.putString("subThoroughfare", address.getSubThoroughfare());
189
+ addressJson.putString("subLocality", address.getSubLocality());
190
+ addressJson.putString("administrativeArea", address.getAdminArea());
191
+ addressJson.putString("subAdministrativeArea", address.getSubAdminArea());
192
+ addressJson.putString("postalCode", address.getPostalCode());
193
+ addressJson.putString("countryCode", address.getCountryCode());
194
+ addressJson.putString("country", address.getCountryName());
195
+
196
+ promise.resolve(addressJson);
197
+ } catch (IOException e) {
198
+ promise.reject("Can not get address location");
199
+ }
203
200
 
204
- uiBlock.addToUIManager();
205
- }
201
+ return null;
202
+ });
203
+
204
+ uiBlock.addToUIManager();
205
+ }
206
206
 
207
- @ReactMethod
208
- public void pointForCoordinate(final int tag, ReadableMap coordinate, final Promise promise) {
209
- final ReactApplicationContext context = getReactApplicationContext();
210
- final double density = (double) context.getResources().getDisplayMetrics().density;
207
+ @ReactMethod
208
+ public void pointForCoordinate(final int tag, ReadableMap coordinate, final Promise promise) {
209
+ final ReactApplicationContext context = getReactApplicationContext();
210
+ final double density = (double) context.getResources().getDisplayMetrics().density;
211
211
 
212
- final LatLng coord = new LatLng(
213
- coordinate.hasKey("latitude") ? coordinate.getDouble("latitude") : 0.0,
214
- coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
215
- );
212
+ final LatLng coord = new LatLng(
213
+ coordinate.hasKey("latitude") ? coordinate.getDouble("latitude") : 0.0,
214
+ coordinate.hasKey("longitude") ? coordinate.getDouble("longitude") : 0.0
215
+ );
216
216
 
217
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
218
- Point pt = view.map.getProjection().toScreenLocation(coord);
217
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
218
+ Point pt = view.map.getProjection().toScreenLocation(coord);
219
219
 
220
- WritableMap ptJson = new WritableNativeMap();
221
- ptJson.putDouble("x", (double)pt.x / density);
222
- ptJson.putDouble("y", (double)pt.y / density);
220
+ WritableMap ptJson = new WritableNativeMap();
221
+ ptJson.putDouble("x", (double) pt.x / density);
222
+ ptJson.putDouble("y", (double) pt.y / density);
223
223
 
224
- promise.resolve(ptJson);
224
+ promise.resolve(ptJson);
225
225
 
226
- return null;
227
- });
226
+ return null;
227
+ });
228
228
 
229
- uiBlock.addToUIManager();
230
- }
229
+ uiBlock.addToUIManager();
230
+ }
231
231
 
232
- @ReactMethod
233
- public void coordinateForPoint(final int tag, ReadableMap point, final Promise promise) {
234
- final ReactApplicationContext context = getReactApplicationContext();
235
- final double density = (double) context.getResources().getDisplayMetrics().density;
232
+ @ReactMethod
233
+ public void coordinateForPoint(final int tag, ReadableMap point, final Promise promise) {
234
+ final ReactApplicationContext context = getReactApplicationContext();
235
+ final double density = (double) context.getResources().getDisplayMetrics().density;
236
236
 
237
- final Point pt = new Point(
238
- point.hasKey("x") ? (int)(point.getDouble("x") * density) : 0,
239
- point.hasKey("y") ? (int)(point.getDouble("y") * density) : 0
240
- );
237
+ final Point pt = new Point(
238
+ point.hasKey("x") ? (int) (point.getDouble("x") * density) : 0,
239
+ point.hasKey("y") ? (int) (point.getDouble("y") * density) : 0
240
+ );
241
241
 
242
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
243
- LatLng coord = view.map.getProjection().fromScreenLocation(pt);
242
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
243
+ LatLng coord = view.map.getProjection().fromScreenLocation(pt);
244
244
 
245
- WritableMap coordJson = new WritableNativeMap();
246
- coordJson.putDouble("latitude", coord.latitude);
247
- coordJson.putDouble("longitude", coord.longitude);
245
+ WritableMap coordJson = new WritableNativeMap();
246
+ coordJson.putDouble("latitude", coord.latitude);
247
+ coordJson.putDouble("longitude", coord.longitude);
248
248
 
249
- promise.resolve(coordJson);
249
+ promise.resolve(coordJson);
250
250
 
251
- return null;
252
- });
251
+ return null;
252
+ });
253
253
 
254
- uiBlock.addToUIManager();
255
- }
254
+ uiBlock.addToUIManager();
255
+ }
256
256
 
257
- @ReactMethod
258
- public void getMapBoundaries(final int tag, final Promise promise) {
259
- final ReactApplicationContext context = getReactApplicationContext();
257
+ @ReactMethod
258
+ public void getMapBoundaries(final int tag, final Promise promise) {
259
+ final ReactApplicationContext context = getReactApplicationContext();
260
260
 
261
- MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
262
- double[][] boundaries = view.getMapBoundaries();
261
+ MapUIBlock uiBlock = new MapUIBlock(tag, promise, context, view -> {
262
+ double[][] boundaries = view.getMapBoundaries();
263
263
 
264
- WritableMap coordinates = new WritableNativeMap();
265
- WritableMap northEastHash = new WritableNativeMap();
266
- WritableMap southWestHash = new WritableNativeMap();
264
+ WritableMap coordinates = new WritableNativeMap();
265
+ WritableMap northEastHash = new WritableNativeMap();
266
+ WritableMap southWestHash = new WritableNativeMap();
267
267
 
268
- northEastHash.putDouble("longitude", boundaries[0][0]);
269
- northEastHash.putDouble("latitude", boundaries[0][1]);
270
- southWestHash.putDouble("longitude", boundaries[1][0]);
271
- southWestHash.putDouble("latitude", boundaries[1][1]);
268
+ northEastHash.putDouble("longitude", boundaries[0][0]);
269
+ northEastHash.putDouble("latitude", boundaries[0][1]);
270
+ southWestHash.putDouble("longitude", boundaries[1][0]);
271
+ southWestHash.putDouble("latitude", boundaries[1][1]);
272
272
 
273
- coordinates.putMap("northEast", northEastHash);
274
- coordinates.putMap("southWest", southWestHash);
273
+ coordinates.putMap("northEast", northEastHash);
274
+ coordinates.putMap("southWest", southWestHash);
275
275
 
276
- promise.resolve(coordinates);
276
+ promise.resolve(coordinates);
277
277
 
278
- return null;
279
- });
278
+ return null;
279
+ });
280
280
 
281
- uiBlock.addToUIManager();
282
- }
281
+ uiBlock.addToUIManager();
282
+ }
283
283
  }
@@ -253,16 +253,19 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
253
253
  }
254
254
 
255
255
  private <T extends Event> void dispatchEvent(WritableMap payload, EventCreator<T> creator) {
256
+ dispatchEvent(payload, creator, getId(), context);
257
+ }
258
+ public static <T extends Event> void dispatchEvent(WritableMap payload, EventCreator<T> creator, int viewId, ReactContext context){
256
259
  // Cast context to ReactContext
257
260
  ReactContext reactContext = context;
258
261
 
259
262
  // Get the event dispatcher
260
- EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, getId());
263
+ EventDispatcher eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, viewId);
261
264
 
262
265
  // If there is a dispatcher, create and dispatch the event
263
266
  if (eventDispatcher != null) {
264
267
  int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
265
- T event = creator.create(surfaceId, getId(), payload);
268
+ T event = creator.create(surfaceId, viewId, payload);
266
269
  eventDispatcher.dispatchEvent(event);
267
270
  }
268
271
  }
@@ -401,25 +404,22 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
401
404
  }
402
405
  });
403
406
 
404
- markerCollection.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
405
- @Override
406
- public void onInfoWindowClick(@NonNull Marker marker) {
407
- WritableMap event = makeClickEventData(marker.getPosition());
408
- event.putString("action", "callout-press");
409
- // todo: use Fabric events
410
- // manager.pushEvent(context, view, "onCalloutPress", event);
407
+ markerCollection.setOnInfoWindowClickListener(marker -> {
408
+ WritableMap event = makeClickEventData(marker.getPosition());
409
+ event.putString("action", "callout-press");
410
+ dispatchEvent(event, OnCalloutPressEvent::new);
411
411
 
412
- event = makeClickEventData(marker.getPosition());
413
- event.putString("action", "callout-press");
414
- MapMarker markerView = getMarkerMap(marker);
415
- // todo: use Fabric events
416
- // manager.pushEvent(context, markerView, "onCalloutPress", event);
417
412
 
413
+ event = makeClickEventData(marker.getPosition());
414
+ event.putString("action", "callout-press");
415
+ MapMarker markerView = getMarkerMap(marker);
416
+ dispatchEvent(event, OnCalloutPressEvent::new, markerView.getId(), context);
417
+
418
+ MapCallout infoWindow = markerView.getCalloutView();
419
+ if (infoWindow != null) {
418
420
  event = makeClickEventData(marker.getPosition());
419
421
  event.putString("action", "callout-press");
420
- MapCallout infoWindow = markerView.getCalloutView();
421
- // todo: use Fabric events
422
- // if (infoWindow != null) manager.pushEvent(context, infoWindow, "onPress", event);
422
+ dispatchEvent(event, OnPressEvent::new, infoWindow.getId(), context);
423
423
  }
424
424
  });
425
425
 
@@ -460,6 +460,7 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
460
460
  boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason;
461
461
  WritableMap event = new WritableNativeMap();
462
462
  event.putBoolean("isGesture", isGesture);
463
+ // dispatchEvent(event, OnRegionChangeEvent::new);
463
464
  // todo: use Fabric events
464
465
  // manager.pushEvent(context, view, "onRegionChangeStart", event);
465
466
  }
package/lib/MapView.js CHANGED
@@ -206,15 +206,9 @@ class MapView extends React.Component {
206
206
  if (config.result !== 'file' && config.result !== 'base64') {
207
207
  throw new Error('Invalid result specified');
208
208
  }
209
- // Call native function
210
- if (react_native_1.Platform.OS === 'android') {
211
- return react_native_1.NativeModules.AirMapModule.takeSnapshot(this._getHandle(), config);
212
- }
213
- else if (react_native_1.Platform.OS === 'ios') {
214
- if (this.fabricMap.current) {
215
- // @ts-ignore
216
- return this.fabricMap.current.takeSnapshot(config);
217
- }
209
+ if (this.fabricMap.current) {
210
+ // @ts-ignore
211
+ return this.fabricMap.current.takeSnapshot(config);
218
212
  }
219
213
  return Promise.reject('takeSnapshot not supported on this platform');
220
214
  }
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.66",
8
+ "version": "1.21.0-alpha.68",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",