1212#import " AIRGMSMarker.h"
1313#import " AIRGoogleMapCallout.h"
1414#import " DummyView.h"
15- #import " GlobalVars.h"
1615
1716CGRect unionRect (CGRect a, CGRect b) {
1817 return CGRectMake (
@@ -37,7 +36,6 @@ - (instancetype)init
3736 if ((self = [super init ])) {
3837 _realMarker = [[AIRGMSMarker alloc ] init ];
3938 _realMarker.fakeMarker = self;
40- _realMarker.appearAnimation = kGMSMarkerAnimationPop ;
4139 }
4240 return self;
4341}
@@ -94,18 +92,6 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
9492 [super insertReactSubview: (UIView*)dummySubview atIndex: atIndex];
9593}
9694
97- - (void )setIcon : (UIImage*)image {
98- CGImageRef cgref = [image CGImage ];
99- CIImage *cim = [image CIImage ];
100-
101- if (cim == nil && cgref == NULL ) {
102- // image does not contain image data
103- _realMarker.icon = [GMSMarker markerImageWithColor: UIColor.blueColor];
104- } else {
105- _realMarker.icon = image;
106- }
107- }
108-
10995- (void )removeReactSubview : (id <RCTComponent>)dummySubview {
11096 UIView* subview = ((DummyView*)dummySubview).view ;
11197
@@ -202,8 +188,70 @@ - (void)setOpacity:(double)opacity
202188
203189- (void )setImageSrc : (NSString *)imageSrc
204190{
205- UIImage * image = [[GlobalVars sharedInstance ] getSharedUIImage: imageSrc];
206- [self setIcon: image];
191+ _imageSrc = imageSrc;
192+
193+ if (_reloadImageCancellationBlock) {
194+ _reloadImageCancellationBlock ();
195+ _reloadImageCancellationBlock = nil ;
196+ }
197+
198+ if (!_imageSrc) {
199+ if (_iconImageView) [_iconImageView removeFromSuperview ];
200+ return ;
201+ }
202+
203+ if (!_iconImageView) {
204+ // prevent glitch with marker (cf. https://github.com/airbnb/react-native-maps/issues/738)
205+ UIImageView *empyImageView = [[UIImageView alloc ] init ];
206+ _iconImageView = empyImageView;
207+ [self iconViewInsertSubview: _iconImageView atIndex: 0 ];
208+ }
209+
210+ _reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest: [RCTConvert NSURLRequest: _imageSrc]
211+ size: self .bounds.size
212+ scale: RCTScreenScale ()
213+ clipped: YES
214+ resizeMode: RCTResizeModeCenter
215+ progressBlock: nil
216+ partialLoadBlock: nil
217+ completionBlock: ^(NSError *error, UIImage *image) {
218+ if (error) {
219+ // TODO(lmr): do something with the error?
220+ NSLog (@" %@ " , error);
221+ }
222+ dispatch_async (dispatch_get_main_queue (), ^{
223+
224+ // TODO(gil): This way allows different image sizes
225+ if (_iconImageView) [_iconImageView removeFromSuperview ];
226+
227+ // ... but this way is more efficient?
228+ // if (_iconImageView) {
229+ // [_iconImageView setImage:image];
230+ // return;
231+ // }
232+
233+ UIImageView *imageView = [[UIImageView alloc ] initWithImage: image];
234+
235+ // TODO: w,h or pixel density could be a prop.
236+ float density = 1 ;
237+ float w = image.size .width /density;
238+ float h = image.size .height /density;
239+ CGRect bounds = CGRectMake (0 , 0 , w, h);
240+
241+ imageView.contentMode = UIViewContentModeScaleAspectFit;
242+ [imageView setFrame: bounds];
243+
244+ // NOTE: sizeToFit doesn't work instead. Not sure why.
245+ // TODO: Doing it this way is not ideal because it causes things to reshuffle
246+ // when the image loads IF the image is larger than the UIView.
247+ // Shouldn't required images have size info automatically via RN?
248+ CGRect selfBounds = unionRect (bounds, self.bounds );
249+ [self setFrame: selfBounds];
250+
251+ _iconImageView = imageView;
252+ [self iconViewInsertSubview: imageView atIndex: 0 ];
253+ });
254+ }];
207255}
208256
209257- (void )setTitle : (NSString *)title {
0 commit comments