react-native-maps 1.21.0-alpha.4 → 1.21.0-alpha.41

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.
Files changed (69) hide show
  1. package/android/src/main/java/com/rnmaps/fabric/NativeAirMapsModule.java +51 -0
  2. package/android/src/main/java/com/rnmaps/maps/MapAirModulePackage.java +46 -0
  3. package/ios/AirGoogleMaps/AIRGoogleMap.h +8 -2
  4. package/ios/AirGoogleMaps/AIRGoogleMap.m +179 -11
  5. package/ios/AirGoogleMaps/AIRGoogleMapCircle.h +0 -1
  6. package/ios/AirGoogleMaps/AIRGoogleMapCircle.m +23 -11
  7. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.h +13 -0
  8. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.m +10 -0
  9. package/ios/AirGoogleMaps/AIRGoogleMapManager.h +7 -0
  10. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +30 -119
  11. package/ios/AirGoogleMaps/AIRGoogleMapMarker.h +2 -0
  12. package/ios/AirGoogleMaps/AIRGoogleMapMarker.m +347 -243
  13. package/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +0 -1
  14. package/ios/AirGoogleMaps/AIRGoogleMapOverlay.h +0 -1
  15. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.h +5 -4
  16. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.m +32 -2
  17. package/ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m +3 -3
  18. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.h +3 -2
  19. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.m +2 -3
  20. package/ios/AirGoogleMaps/AIRGoogleMapPolylineManager.m +2 -2
  21. package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.h +1 -1
  22. package/ios/AirGoogleMaps/AIRGoogleMapWMSTile.m +2 -2
  23. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.h +3 -0
  24. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.m +18 -0
  25. package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +26 -0
  26. package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +599 -0
  27. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +25 -0
  28. package/ios/AirGoogleMaps/RNMapsGooglePolygonView.h +26 -0
  29. package/ios/AirGoogleMaps/RNMapsGooglePolygonView.mm +217 -0
  30. package/ios/AirGoogleMaps/RNMapsGooglePolygonViewManager.mm +25 -0
  31. package/ios/AirMaps/AIRMap.h +8 -5
  32. package/ios/AirMaps/AIRMap.m +284 -141
  33. package/ios/AirMaps/AIRMapManager.m +12 -21
  34. package/ios/AirMaps/AIRMapMarker.h +1 -0
  35. package/ios/AirMaps/AIRMapMarker.m +165 -103
  36. package/ios/AirMaps/Callout/SMCalloutView.m +1 -1
  37. package/ios/AirMaps/RCTConvert+AirMap.h +4 -0
  38. package/ios/AirMaps/RCTConvert+AirMap.m +2 -0
  39. package/ios/AirMaps/RNMapsAirModule.h +3 -0
  40. package/ios/AirMaps/RNMapsAirModule.mm +42 -172
  41. package/ios/AirMaps/RNMapsAirModuleDelegate.h +24 -0
  42. package/ios/AirMaps/RNMapsHostVewDelegate.h +17 -0
  43. package/ios/AirMaps/RNMapsMapView.h +6 -3
  44. package/ios/AirMaps/RNMapsMapView.mm +341 -334
  45. package/ios/AirMaps/RNMapsMarkerView.h +24 -0
  46. package/ios/AirMaps/RNMapsMarkerView.mm +422 -0
  47. package/ios/AirMaps/RNMapsMarkerViewManager.mm +21 -0
  48. package/ios/AirMaps/UIView +AirMap.m +20 -0
  49. package/ios/AirMaps/UIView+AirMap.h +11 -0
  50. package/lib/MapMarker.d.ts +15 -2
  51. package/lib/MapMarker.js +53 -9
  52. package/lib/MapMarkerNativeComponent.js +0 -2
  53. package/lib/MapOverlay.d.ts +1 -1
  54. package/lib/MapView.d.ts +5 -22
  55. package/lib/MapView.js +34 -21
  56. package/lib/{FabricMapView.d.ts → createFabricMap.d.ts} +7 -6
  57. package/lib/createFabricMap.js +175 -0
  58. package/lib/decorateMapComponent.js +18 -0
  59. package/lib/specs/NativeAirMapsModule.d.ts +2 -2
  60. package/lib/specs/NativeComponentGoogleMapView.d.ts +713 -0
  61. package/lib/specs/NativeComponentGoogleMapView.js +21 -0
  62. package/lib/specs/NativeComponentGooglePolygon.d.ts +75 -0
  63. package/lib/specs/NativeComponentGooglePolygon.js +9 -0
  64. package/lib/specs/NativeComponentMapView.d.ts +21 -45
  65. package/lib/specs/NativeComponentMarker.d.ts +258 -0
  66. package/lib/specs/NativeComponentMarker.js +21 -0
  67. package/package.json +7 -7
  68. package/react-native-maps.podspec +1 -1
  69. package/lib/FabricMapView.js +0 -175
@@ -16,141 +16,228 @@
16
16
  #import "AIRDummyView.h"
17
17
 
18
18
  CGRect unionRect(CGRect a, CGRect b) {
19
- return CGRectMake(
20
- MIN(a.origin.x, b.origin.x),
21
- MIN(a.origin.y, b.origin.y),
22
- MAX(a.size.width, b.size.width),
23
- MAX(a.size.height, b.size.height));
19
+ return CGRectMake(
20
+ MIN(a.origin.x, b.origin.x),
21
+ MIN(a.origin.y, b.origin.y),
22
+ MAX(a.size.width, b.size.width),
23
+ MAX(a.size.height, b.size.height));
24
24
  }
25
25
 
26
26
  @interface AIRGoogleMapMarker ()
27
27
  @end
28
28
 
29
29
  @implementation AIRGoogleMapMarker {
30
- RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
31
- __weak UIImageView *_iconImageView;
32
- UIView *_iconView;
30
+ RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
31
+ RCTBubblingEventBlock _onPress;
32
+ RCTBubblingEventBlock _onSelect;
33
+ RCTBubblingEventBlock _onDeselect;
34
+ __weak UIImageView *_iconImageView;
35
+ UIView *_iconView;
36
+ UIColor *_pinColor;
37
+ CLLocationCoordinate2D _coordinates;
38
+ CLLocationDegrees _rotation;
39
+ BOOL _tracksInfoWindowChanges;
40
+ BOOL _tracksViewChanges;
41
+ BOOL _draggable;
42
+ BOOL _tappable;
43
+ BOOL _flat;
44
+ double _opacity;
45
+ NSString* _identifier;
46
+ NSString* _title;
47
+ NSString* _subtitle;
48
+
33
49
  }
34
50
 
35
51
  - (instancetype)init
36
52
  {
37
- if ((self = [super init])) {
38
- _realMarker = [[AIRGMSMarker alloc] init];
39
- _realMarker.fakeMarker = self;
40
- _realMarker.tracksViewChanges = true;
41
- _realMarker.tracksInfoWindowChanges = false;
42
- }
43
- return self;
53
+ if ((self = [super init])) {
54
+ _tracksViewChanges = true;
55
+ _tracksInfoWindowChanges = false;
56
+ _tappable = true;
57
+ _opacity = 1.0;
58
+ }
59
+ return self;
44
60
  }
45
61
 
46
62
  - (void)layoutSubviews {
47
- float width = 0;
48
- float height = 0;
63
+ float width = 0;
64
+ float height = 0;
65
+
66
+ for (UIView *v in [_iconView subviews]) {
49
67
 
50
- for (UIView *v in [_iconView subviews]) {
68
+ float fw = v.frame.origin.x + v.frame.size.width;
69
+ float fh = v.frame.origin.y + v.frame.size.height;
51
70
 
52
- float fw = v.frame.origin.x + v.frame.size.width;
53
- float fh = v.frame.origin.y + v.frame.size.height;
71
+ width = MAX(fw, width);
72
+ height = MAX(fh, height);
73
+ }
74
+
75
+ [_iconView setFrame:CGRectMake(0, 0, width, height)];
76
+ }
54
77
 
55
- width = MAX(fw, width);
56
- height = MAX(fh, height);
57
- }
58
78
 
59
- [_iconView setFrame:CGRectMake(0, 0, width, height)];
79
+ - (UIView *) iconView
80
+ {
81
+ return _iconView;
60
82
  }
61
83
 
84
+ - (void) didUpdateReactSubviews
85
+ {
86
+ [super didUpdateReactSubviews];
87
+ if (_iconView){
88
+ [_iconView setFrame:self.frame];
89
+ }
90
+ }
62
91
 
92
+ - (void) didInsertInMap:(AIRGoogleMap *) map
93
+ {
94
+ _realMarker = [AIRGMSMarker new];
95
+ _realMarker.fakeMarker = self;
96
+ _realMarker.tracksViewChanges = _tracksViewChanges;
97
+ _realMarker.tracksInfoWindowChanges = _tracksInfoWindowChanges;
98
+
99
+ [_realMarker setPosition:_coordinates];
100
+ if (_iconView){
101
+ [_realMarker setIconView:_iconView];
102
+ }
103
+ if (_rotation != 0){
104
+ [_realMarker setRotation:_rotation];
105
+ }
106
+ if (_identifier){
107
+ [_realMarker setIdentifier:_identifier];
108
+ }
109
+ if (_title){
110
+ [_realMarker setTitle:_title];
111
+ }
112
+ if (_subtitle){
113
+ [_realMarker setSnippet:_subtitle];
114
+ }
115
+ if (!CGPointEqualToPoint(_anchor, CGPointZero)){
116
+ [_realMarker setGroundAnchor:_anchor];
117
+ }
118
+ if (!CGPointEqualToPoint(_calloutAnchor, CGPointZero)){
119
+ [_realMarker setInfoWindowAnchor:_calloutAnchor];
120
+ }
121
+ if (_flat){
122
+ [_realMarker setFlat:_flat];
123
+ }
124
+ if (_draggable){
125
+ [_realMarker setDraggable:_draggable];
126
+ }
127
+ [_realMarker setTappable:_tappable];
128
+ if (_pinColor){
129
+ _realMarker.icon = [GMSMarker markerImageWithColor:_pinColor];
130
+ }
131
+ if (_opacity != 1.0){
132
+ [_realMarker setOpacity:_opacity];
133
+ }
134
+ if (_onSelect){
135
+ [_realMarker setOnSelect:_onSelect];
136
+ }
137
+ if (_onDeselect){
138
+ [_realMarker setOnDeselect:_onDeselect];
139
+ }
140
+ if (_onPress){
141
+ [_realMarker setOnPress:_onPress];
142
+ }
143
+ if (_zIndex){
144
+ [_realMarker setZIndex:_zIndex];
145
+ }
146
+ [_realMarker setMap:map];
147
+ }
63
148
 
64
149
  - (void)iconViewInsertSubview:(UIView*)subview atIndex:(NSInteger)atIndex {
65
- if (!_realMarker.iconView) {
66
- _iconView = [[UIView alloc] init];
67
- _realMarker.iconView = _iconView;
68
- }
69
- [_iconView insertSubview:subview atIndex:atIndex];
150
+ if (!_iconView){
151
+ _iconView = [[UIView alloc] init];
152
+ }
153
+ if (!_realMarker.iconView) {
154
+ _realMarker.iconView = _iconView;
155
+ }
156
+ [_iconView insertSubview:subview atIndex:atIndex];
70
157
  }
71
158
 
72
159
  - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex {
73
- if ([subview isKindOfClass:[AIRGoogleMapCallout class]]) {
74
- self.calloutView = (AIRGoogleMapCallout *)subview;
75
- } else { // a child view of the marker
76
- [self iconViewInsertSubview:(UIView*)subview atIndex:atIndex+1];
77
- }
78
- AIRDummyView *dummySubview = [[AIRDummyView alloc] initWithView:(UIView *)subview];
79
- [super insertReactSubview:(UIView*)dummySubview atIndex:atIndex];
160
+ if ([subview isKindOfClass:[AIRGoogleMapCallout class]]) {
161
+ self.calloutView = (AIRGoogleMapCallout *)subview;
162
+ } else { // a child view of the marker
163
+ [self iconViewInsertSubview:(UIView*)subview atIndex:atIndex+1];
164
+ }
165
+ AIRDummyView *dummySubview = [[AIRDummyView alloc] initWithView:(UIView *)subview];
166
+ [super insertReactSubview:(UIView*)dummySubview atIndex:atIndex];
80
167
  }
81
168
 
82
169
  - (void)removeReactSubview:(id<RCTComponent>)dummySubview {
83
- UIView *subview = [dummySubview isKindOfClass:[AIRDummyView class]] ? ((AIRDummyView *)dummySubview).view : (UIView *)dummySubview;
170
+ UIView *subview = [dummySubview isKindOfClass:[AIRDummyView class]] ? ((AIRDummyView *)dummySubview).view : (UIView *)dummySubview;
84
171
 
85
- if ([subview isKindOfClass:[AIRGoogleMapCallout class]]) {
86
- self.calloutView = nil;
87
- } else {
88
- [subview removeFromSuperview];
89
- }
90
- [super removeReactSubview:(UIView*)dummySubview];
172
+ if ([subview isKindOfClass:[AIRGoogleMapCallout class]]) {
173
+ self.calloutView = nil;
174
+ } else {
175
+ [subview removeFromSuperview];
176
+ }
177
+ [super removeReactSubview:(UIView*)dummySubview];
91
178
  }
92
179
 
93
180
  - (void)showCalloutView {
94
- [_realMarker.map setSelectedMarker:_realMarker];
181
+ [_realMarker.map setSelectedMarker:_realMarker];
95
182
  }
96
183
 
97
184
  - (void)hideCalloutView {
98
- [_realMarker.map setSelectedMarker:Nil];
185
+ [_realMarker.map setSelectedMarker:Nil];
99
186
  }
100
187
 
101
188
  - (void)redraw {
102
- if (!_realMarker.iconView) return;
189
+ if (!_realMarker.iconView) return;
103
190
 
104
- BOOL oldValue = _realMarker.tracksViewChanges;
191
+ BOOL oldValue = _realMarker.tracksViewChanges;
105
192
 
106
- if (oldValue == YES)
107
- {
108
- // Immediate refresh, like right now. Not waiting for next frame.
109
- UIView *view = _realMarker.iconView;
110
- _realMarker.iconView = nil;
111
- _realMarker.iconView = view;
112
- }
113
- else
114
- {
115
- // Refresh according to docs
116
- _realMarker.tracksViewChanges = YES;
117
- _realMarker.tracksViewChanges = NO;
118
- }
193
+ if (oldValue == YES)
194
+ {
195
+ // Immediate refresh, like right now. Not waiting for next frame.
196
+ UIView *view = _realMarker.iconView;
197
+ _realMarker.iconView = nil;
198
+ _realMarker.iconView = view;
199
+ }
200
+ else
201
+ {
202
+ // Refresh according to docs
203
+ _realMarker.tracksViewChanges = YES;
204
+ _realMarker.tracksViewChanges = NO;
205
+ }
119
206
  }
120
207
 
121
208
  - (UIView *)markerInfoContents {
122
- if (self.calloutView && !self.calloutView.tooltip) {
123
- return self.calloutView;
124
- }
125
- return nil;
209
+ if (self.calloutView && !self.calloutView.tooltip) {
210
+ return self.calloutView;
211
+ }
212
+ return nil;
126
213
  }
127
214
 
128
215
  - (UIView *)markerInfoWindow {
129
- if (self.calloutView && self.calloutView.tooltip) {
130
- return self.calloutView;
131
- }
132
- return nil;
216
+ if (self.calloutView && self.calloutView.tooltip) {
217
+ return self.calloutView;
218
+ }
219
+ return nil;
133
220
  }
134
221
 
135
222
  - (void)didTapInfoWindowOfMarker:(AIRGMSMarker *)marker point:(CGPoint)point frame:(CGRect)frame {
136
- if (self.calloutView && self.calloutView.onPress) {
137
- //todo: why not 'callout-press' ?
138
- id event = @{
139
- @"action": @"marker-overlay-press",
140
- @"id": self.identifier ?: @"unknown",
141
- @"point": @{
142
- @"x": @(point.x),
143
- @"y": @(point.y),
144
- },
145
- @"frame": @{
146
- @"x": @(frame.origin.x),
147
- @"y": @(frame.origin.y),
148
- @"width": @(frame.size.width),
149
- @"height": @(frame.size.height),
150
- }
151
- };
152
- self.calloutView.onPress(event);
153
- }
223
+ if (self.calloutView && self.calloutView.onPress) {
224
+ //todo: why not 'callout-press' ?
225
+ id event = @{
226
+ @"action": @"marker-overlay-press",
227
+ @"id": self.identifier ?: @"unknown",
228
+ @"point": @{
229
+ @"x": @(point.x),
230
+ @"y": @(point.y),
231
+ },
232
+ @"frame": @{
233
+ @"x": @(frame.origin.x),
234
+ @"y": @(frame.origin.y),
235
+ @"width": @(frame.size.width),
236
+ @"height": @(frame.size.height),
237
+ }
238
+ };
239
+ self.calloutView.onPress(event);
240
+ }
154
241
  }
155
242
 
156
243
  - (void)didTapInfoWindowOfMarker:(AIRGMSMarker *)marker {
@@ -161,19 +248,19 @@ CGRect unionRect(CGRect a, CGRect b) {
161
248
  if (subview && subview.onPress) {
162
249
  //todo: why not 'callout-inside-press' ?
163
250
  id event = @{
164
- @"action": @"marker-inside-overlay-press",
165
- @"id": self.identifier ?: @"unknown",
166
- @"point": @{
167
- @"x": @(point.x),
168
- @"y": @(point.y),
169
- },
170
- @"frame": @{
171
- @"x": @(frame.origin.x),
172
- @"y": @(frame.origin.y),
173
- @"width": @(frame.size.width),
174
- @"height": @(frame.size.height),
175
- }
176
- };
251
+ @"action": @"marker-inside-overlay-press",
252
+ @"id": self.identifier ?: @"unknown",
253
+ @"point": @{
254
+ @"x": @(point.x),
255
+ @"y": @(point.y),
256
+ },
257
+ @"frame": @{
258
+ @"x": @(frame.origin.x),
259
+ @"y": @(frame.origin.y),
260
+ @"width": @(frame.size.width),
261
+ @"height": @(frame.size.height),
262
+ }
263
+ };
177
264
  subview.onPress(event);
178
265
  } else {
179
266
  [self didTapInfoWindowOfMarker:marker point:point frame:frame];
@@ -181,30 +268,32 @@ CGRect unionRect(CGRect a, CGRect b) {
181
268
  }
182
269
 
183
270
  - (void)didBeginDraggingMarker:(AIRGMSMarker *)marker {
184
- if (!self.onDragStart) return;
185
- self.onDragStart([self makeEventData]);
271
+ if (!self.onDragStart) return;
272
+ self.onDragStart([self makeEventData]);
186
273
  }
187
274
 
188
275
  - (void)didEndDraggingMarker:(AIRGMSMarker *)marker {
189
- if (!self.onDragEnd) return;
190
- self.onDragEnd([self makeEventData]);
276
+ if (!self.onDragEnd) return;
277
+ self.onDragEnd([self makeEventData]);
191
278
  }
192
279
 
193
280
  - (void)didDragMarker:(AIRGMSMarker *)marker {
194
- if (!self.onDrag) return;
195
- self.onDrag([self makeEventData]);
281
+ if (!self.onDrag) return;
282
+ self.onDrag([self makeEventData]);
196
283
  }
197
284
 
198
285
  - (void)setCoordinate:(CLLocationCoordinate2D)coordinate {
199
- _realMarker.position = coordinate;
286
+ _realMarker.position = coordinate;
287
+ _coordinates = coordinate;
200
288
  }
201
289
 
202
290
  - (CLLocationCoordinate2D)coordinate {
203
- return _realMarker.position;
291
+ return _realMarker.position;
204
292
  }
205
293
 
206
294
  - (void)setRotation:(CLLocationDegrees)rotation {
207
295
  _realMarker.rotation = rotation;
296
+ _rotation = rotation;
208
297
  }
209
298
 
210
299
  - (CLLocationDegrees)rotation {
@@ -212,220 +301,235 @@ CGRect unionRect(CGRect a, CGRect b) {
212
301
  }
213
302
 
214
303
  - (void)setIdentifier:(NSString *)identifier {
215
- _realMarker.identifier = identifier;
304
+ _realMarker.identifier = identifier;
305
+ _identifier = identifier;
216
306
  }
217
307
 
218
308
  - (NSString *)identifier {
219
- return _realMarker.identifier;
309
+ return _realMarker.identifier;
220
310
  }
221
311
 
222
312
  - (void)setOnPress:(RCTBubblingEventBlock)onPress {
223
- _realMarker.onPress = onPress;
313
+ _realMarker.onPress = onPress;
314
+ _onPress = onPress;
224
315
  }
225
316
 
226
317
  - (RCTBubblingEventBlock)onPress {
227
- return _realMarker.onPress;
318
+ return _realMarker.onPress;
228
319
  }
229
320
 
230
321
  - (void)setOnSelect:(RCTDirectEventBlock)onSelect {
231
- _realMarker.onSelect = onSelect;
322
+ _realMarker.onSelect = onSelect;
323
+ _onSelect = onSelect;
232
324
  }
233
325
 
234
326
  - (RCTDirectEventBlock)onSelect {
235
- return _realMarker.onSelect;
327
+ return _realMarker.onSelect;
236
328
  }
237
329
 
238
330
  - (void)setOnDeselect:(RCTDirectEventBlock)onDeselect {
239
- _realMarker.onDeselect = onDeselect;
331
+ _realMarker.onDeselect = onDeselect;
332
+ _onDeselect = onDeselect;
240
333
  }
241
334
 
242
335
  - (RCTDirectEventBlock)onDeselect {
243
- return _realMarker.onDeselect;
336
+ return _realMarker.onDeselect;
244
337
  }
245
338
 
246
339
  - (void)setOpacity:(double)opacity
247
340
  {
248
- _realMarker.opacity = opacity;
341
+ _realMarker.opacity = opacity;
342
+ _opacity = opacity;
249
343
  }
250
344
 
251
345
  - (void)setImageSrc:(NSString *)imageSrc
252
346
  {
253
- _imageSrc = imageSrc;
254
-
255
- if (_reloadImageCancellationBlock) {
256
- _reloadImageCancellationBlock();
257
- _reloadImageCancellationBlock = nil;
258
- }
259
-
260
- if (!_imageSrc) {
261
- if (_iconImageView) [_iconImageView removeFromSuperview];
262
- return;
263
- }
264
-
265
- if (!_iconImageView) {
266
- // prevent glitch with marker (cf. https://github.com/react-native-maps/react-native-maps/issues/738)
267
- UIImageView *empyImageView = [[UIImageView alloc] init];
268
- _iconImageView = empyImageView;
269
- [self iconViewInsertSubview:_iconImageView atIndex:0];
270
- }
271
-
272
- _reloadImageCancellationBlock = [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
273
- size:self.bounds.size
274
- scale:RCTScreenScale()
275
- clipped:YES
276
- resizeMode:RCTResizeModeCenter
277
- progressBlock:nil
278
- partialLoadBlock:nil
279
- completionBlock:^(NSError *error, UIImage *image) {
280
- if (error) {
281
- // TODO(lmr): do something with the error?
282
- NSLog(@"%@", error);
283
- }
284
- dispatch_async(dispatch_get_main_queue(), ^{
285
-
286
- // TODO(gil): This way allows different image sizes
287
- if (self->_iconImageView) [self->_iconImageView removeFromSuperview];
288
-
289
- // ... but this way is more efficient?
290
- // if (_iconImageView) {
291
- // [_iconImageView setImage:image];
292
- // return;
293
- // }
294
-
295
- UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
296
-
297
- // TODO: w,h or pixel density could be a prop.
298
- float density = 1;
299
- float w = image.size.width/density;
300
- float h = image.size.height/density;
301
- CGRect bounds = CGRectMake(0, 0, w, h);
302
-
303
- imageView.contentMode = UIViewContentModeScaleAspectFit;
304
- [imageView setFrame:bounds];
305
-
306
- // NOTE: sizeToFit doesn't work instead. Not sure why.
307
- // TODO: Doing it this way is not ideal because it causes things to reshuffle
308
- // when the image loads IF the image is larger than the UIView.
309
- // Shouldn't required images have size info automatically via RN?
310
- CGRect selfBounds = unionRect(bounds, self.bounds);
311
- [self setFrame:selfBounds];
312
-
313
- self->_iconImageView = imageView;
314
- [self iconViewInsertSubview:imageView atIndex:0];
315
- });
316
- }];
347
+ _imageSrc = imageSrc;
348
+
349
+ if (_reloadImageCancellationBlock) {
350
+ _reloadImageCancellationBlock();
351
+ _reloadImageCancellationBlock = nil;
352
+ }
353
+
354
+ if (!_imageSrc) {
355
+ if (_iconImageView) [_iconImageView removeFromSuperview];
356
+ return;
357
+ }
358
+
359
+ if (!_iconImageView) {
360
+ // prevent glitch with marker (cf. https://github.com/react-native-maps/react-native-maps/issues/738)
361
+ UIImageView *empyImageView = [[UIImageView alloc] init];
362
+ _iconImageView = empyImageView;
363
+ [self iconViewInsertSubview:_iconImageView atIndex:0];
364
+ }
365
+ __weak AIRGoogleMapMarker* weakSelf = self;
366
+
367
+ _reloadImageCancellationBlock = [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
368
+ size:self.bounds.size
369
+ scale:RCTScreenScale()
370
+ clipped:YES
371
+ resizeMode:RCTResizeModeCenter
372
+ progressBlock:nil
373
+ partialLoadBlock:nil
374
+ completionBlock:^(NSError *error, UIImage *image) {
375
+ if (error) {
376
+ // TODO(lmr): do something with the error?
377
+ NSLog(@"%@", error);
378
+ }
379
+
380
+ dispatch_async(dispatch_get_main_queue(), ^{
381
+ __strong AIRGoogleMapMarker* strongSelf = weakSelf;
382
+
383
+ // TODO(gil): This way allows different image sizes
384
+ if (strongSelf->_iconImageView) [strongSelf->_iconImageView removeFromSuperview];
385
+
386
+ // ... but this way is more efficient?
387
+ // if (_iconImageView) {
388
+ // [_iconImageView setImage:image];
389
+ // return;
390
+ // }
391
+
392
+ UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
393
+
394
+ // TODO: w,h or pixel density could be a prop.
395
+ float density = 1;
396
+ float w = image.size.width/density;
397
+ float h = image.size.height/density;
398
+ CGRect bounds = CGRectMake(0, 0, w, h);
399
+
400
+ imageView.contentMode = UIViewContentModeScaleAspectFit;
401
+ [imageView setFrame:bounds];
402
+
403
+ // NOTE: sizeToFit doesn't work instead. Not sure why.
404
+ // TODO: Doing it this way is not ideal because it causes things to reshuffle
405
+ // when the image loads IF the image is larger than the UIView.
406
+ // Shouldn't required images have size info automatically via RN?
407
+ CGRect selfBounds = unionRect(bounds, self.bounds);
408
+ [strongSelf setFrame:selfBounds];
409
+
410
+ strongSelf->_iconImageView = imageView;
411
+ [strongSelf iconViewInsertSubview:imageView atIndex:0];
412
+ [strongSelf layoutSubviews];
413
+ [strongSelf.realMarker setIconView:strongSelf.iconView];
414
+ });
415
+ }];
317
416
  }
318
417
 
319
418
  - (void)setIconSrc:(NSString *)iconSrc
320
419
  {
321
- _iconSrc = iconSrc;
322
-
323
- if (_reloadImageCancellationBlock) {
324
- _reloadImageCancellationBlock();
325
- _reloadImageCancellationBlock = nil;
326
- }
327
-
328
- if (!_realMarker.icon) {
329
- // prevent glitch with marker (cf. https://github.com/react-native-maps/react-native-maps/issues/3657)
330
- UIImage *emptyImage = [[UIImage alloc] init];
331
- _realMarker.icon = emptyImage;
332
- }
333
-
334
- _reloadImageCancellationBlock =
335
- [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_iconSrc]
336
- size:self.bounds.size
337
- scale:RCTScreenScale()
338
- clipped:YES
339
- resizeMode:RCTResizeModeCenter
340
- progressBlock:nil
341
- partialLoadBlock:nil
342
- completionBlock:^(NSError *error, UIImage *image) {
343
- if (error) {
344
- // TODO(lmr): do something with the error?
345
- NSLog(@"%@", error);
346
- }
347
- dispatch_async(dispatch_get_main_queue(), ^{
348
- self->_realMarker.icon = image;
349
- });
350
- }];
420
+ _iconSrc = iconSrc;
421
+
422
+ if (_reloadImageCancellationBlock) {
423
+ _reloadImageCancellationBlock();
424
+ _reloadImageCancellationBlock = nil;
425
+ }
426
+
427
+ if (!_realMarker.icon) {
428
+ // prevent glitch with marker (cf. https://github.com/react-native-maps/react-native-maps/issues/3657)
429
+ UIImage *emptyImage = [[UIImage alloc] init];
430
+ _realMarker.icon = emptyImage;
431
+ }
432
+
433
+ _reloadImageCancellationBlock =
434
+ [[_bridge moduleForName:@"ImageLoader"] loadImageWithURLRequest:[RCTConvert NSURLRequest:_iconSrc]
435
+ size:self.bounds.size
436
+ scale:RCTScreenScale()
437
+ clipped:YES
438
+ resizeMode:RCTResizeModeCenter
439
+ progressBlock:nil
440
+ partialLoadBlock:nil
441
+ completionBlock:^(NSError *error, UIImage *image) {
442
+ if (error) {
443
+ // TODO(lmr): do something with the error?
444
+ NSLog(@"%@", error);
445
+ }
446
+ dispatch_async(dispatch_get_main_queue(), ^{
447
+ self->_realMarker.icon = image;
448
+ });
449
+ }];
351
450
  }
352
451
 
353
452
  - (void)setTitle:(NSString *)title {
354
- _realMarker.title = [title copy];
453
+ _realMarker.title = [title copy];
454
+ _title = title;
355
455
  }
356
456
 
357
457
  - (NSString *)title {
358
- return _realMarker.title;
458
+ return _realMarker.title;
359
459
  }
360
460
 
361
461
  - (void)setSubtitle:(NSString *)subtitle {
362
- _realMarker.snippet = subtitle;
462
+ _realMarker.snippet = subtitle;
463
+ _subtitle = subtitle;
363
464
  }
364
465
 
365
466
  - (NSString *)subtitle {
366
- return _realMarker.snippet;
467
+ return _realMarker.snippet;
367
468
  }
368
469
 
369
470
  - (void)setPinColor:(UIColor *)pinColor {
370
- _pinColor = pinColor;
371
- _realMarker.icon = [GMSMarker markerImageWithColor:pinColor];
471
+ _pinColor = pinColor;
472
+ _realMarker.icon = [GMSMarker markerImageWithColor:pinColor];
372
473
  }
373
474
 
374
475
  - (void)setAnchor:(CGPoint)anchor {
375
- _anchor = anchor;
376
- _realMarker.groundAnchor = anchor;
476
+ _anchor = anchor;
477
+ _realMarker.groundAnchor = anchor;
377
478
  }
378
479
 
379
480
  - (void)setCalloutAnchor:(CGPoint)calloutAnchor {
380
- _calloutAnchor = calloutAnchor;
381
- _realMarker.infoWindowAnchor = calloutAnchor;
481
+ _calloutAnchor = calloutAnchor;
482
+ _realMarker.infoWindowAnchor = calloutAnchor;
382
483
  }
383
484
 
384
485
 
385
486
  - (void)setZIndex:(NSInteger)zIndex
386
487
  {
387
- _zIndex = zIndex;
388
- _realMarker.zIndex = (int)zIndex;
488
+ _zIndex = zIndex;
489
+ _realMarker.zIndex = (int)zIndex;
389
490
  }
390
491
 
391
492
  - (void)setDraggable:(BOOL)draggable {
392
- _realMarker.draggable = draggable;
493
+ _realMarker.draggable = draggable;
494
+ _draggable = draggable;
393
495
  }
394
496
 
395
497
  - (BOOL)draggable {
396
- return _realMarker.draggable;
498
+ return _realMarker.draggable;
397
499
  }
398
500
 
399
501
  - (void)setTappable:(BOOL)tappable {
400
- _realMarker.tappable = tappable;
502
+ _realMarker.tappable = tappable;
503
+ _tappable = tappable;
401
504
  }
402
505
 
403
506
  - (BOOL)tappable {
404
- return _realMarker.tappable;
507
+ return _realMarker.tappable;
405
508
  }
406
509
 
407
510
  - (void)setFlat:(BOOL)flat {
408
- _realMarker.flat = flat;
511
+ _realMarker.flat = flat;
512
+ _flat = flat;
409
513
  }
410
514
 
411
515
  - (BOOL)flat {
412
- return _realMarker.flat;
516
+ return _realMarker.flat;
413
517
  }
414
518
 
415
519
  - (void)setTracksViewChanges:(BOOL)tracksViewChanges {
416
- _realMarker.tracksViewChanges = tracksViewChanges;
520
+ _realMarker.tracksViewChanges = tracksViewChanges;
417
521
  }
418
522
 
419
523
  - (BOOL)tracksViewChanges {
420
- return _realMarker.tracksViewChanges;
524
+ return _realMarker.tracksViewChanges;
421
525
  }
422
526
 
423
527
  - (void)setTracksInfoWindowChanges:(BOOL)tracksInfoWindowChanges {
424
- _realMarker.tracksInfoWindowChanges = tracksInfoWindowChanges;
528
+ _realMarker.tracksInfoWindowChanges = tracksInfoWindowChanges;
425
529
  }
426
530
 
427
531
  - (BOOL)tracksInfoWindowChanges {
428
- return _realMarker.tracksInfoWindowChanges;
532
+ return _realMarker.tracksInfoWindowChanges;
429
533
  }
430
534
 
431
535
 
@@ -434,17 +538,17 @@ CGRect unionRect(CGRect a, CGRect b) {
434
538
  CGPoint position = [self.realMarker.map.projection pointForCoordinate:coordinate];
435
539
 
436
540
  return @{
437
- @"id": self.identifier ?: @"unknown",
438
- @"position": @{
439
- @"x": @(position.x),
440
- @"y": @(position.y),
441
- },
442
- @"coordinate": @{
443
- @"latitude": @(coordinate.latitude),
444
- @"longitude": @(coordinate.longitude),
445
- },
446
- @"action": action,
447
- };
541
+ @"id": self.identifier ?: @"unknown",
542
+ @"position": @{
543
+ @"x": @(position.x),
544
+ @"y": @(position.y),
545
+ },
546
+ @"coordinate": @{
547
+ @"latitude": @(coordinate.latitude),
548
+ @"longitude": @(coordinate.longitude),
549
+ },
550
+ @"action": action,
551
+ };
448
552
  }
449
553
 
450
554
  - (id)makeEventData {