react-native-maps 1.21.0-alpha.3 → 1.21.0-alpha.30

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