1212#import " AIRGMSMarker.h"
1313#import " AIRGoogleMapCallout.h"
1414#import " DummyView.h"
15+ #import " GlobalVars.h"
1516
1617CGRect unionRect (CGRect a, CGRect b) {
1718 return CGRectMake (
@@ -36,6 +37,7 @@ - (instancetype)init
3637 if ((self = [super init ])) {
3738 _realMarker = [[AIRGMSMarker alloc ] init ];
3839 _realMarker.fakeMarker = self;
40+ _realMarker.appearAnimation = kGMSMarkerAnimationPop ;
3941 }
4042 return self;
4143}
@@ -92,6 +94,18 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
9294 [super insertReactSubview: (UIView*)dummySubview atIndex: atIndex];
9395}
9496
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+
95109- (void )removeReactSubview : (id <RCTComponent>)dummySubview {
96110 UIView* subview = ((DummyView*)dummySubview).view ;
97111
@@ -188,70 +202,8 @@ - (void)setOpacity:(double)opacity
188202
189203- (void )setImageSrc : (NSString *)imageSrc
190204{
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- }];
205+ UIImage * image = [[GlobalVars sharedInstance ] getSharedUIImage: imageSrc];
206+ [self setIcon: image];
255207}
256208
257209- (void )setTitle : (NSString *)title {
0 commit comments