Skip to content

Commit

Permalink
Revert "Issue1176 improve ios marker performance by X100 (react-nativ…
Browse files Browse the repository at this point in the history
…e-maps#1187)"

This reverts commit b908c08.
  • Loading branch information
christopherdro authored and codedre committed Aug 17, 2017
1 parent 667bf39 commit 6952e17
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 92 deletions.
80 changes: 64 additions & 16 deletions lib/ios/AirGoogleMaps/AIRGoogleMapMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#import "AIRGMSMarker.h"
#import "AIRGoogleMapCallout.h"
#import "DummyView.h"
#import "GlobalVars.h"

CGRect unionRect(CGRect a, CGRect b) {
return CGRectMake(
Expand All @@ -37,7 +36,6 @@ - (instancetype)init
if ((self = [super init])) {
_realMarker = [[AIRGMSMarker alloc] init];
_realMarker.fakeMarker = self;
_realMarker.appearAnimation = kGMSMarkerAnimationPop;
}
return self;
}
Expand Down Expand Up @@ -94,18 +92,6 @@ - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
[super insertReactSubview:(UIView*)dummySubview atIndex:atIndex];
}

- (void)setIcon:(UIImage*)image {
CGImageRef cgref = [image CGImage];
CIImage *cim = [image CIImage];

if (cim == nil && cgref == NULL) {
// image does not contain image data
_realMarker.icon = [GMSMarker markerImageWithColor:UIColor.blueColor];
} else {
_realMarker.icon = image;
}
}

- (void)removeReactSubview:(id<RCTComponent>)dummySubview {
UIView* subview = ((DummyView*)dummySubview).view;

Expand Down Expand Up @@ -202,8 +188,70 @@ - (void)setOpacity:(double)opacity

- (void)setImageSrc:(NSString *)imageSrc
{
UIImage * image = [[GlobalVars sharedInstance] getSharedUIImage:imageSrc];
[self setIcon:image];
_imageSrc = imageSrc;

if (_reloadImageCancellationBlock) {
_reloadImageCancellationBlock();
_reloadImageCancellationBlock = nil;
}

if (!_imageSrc) {
if (_iconImageView) [_iconImageView removeFromSuperview];
return;
}

if (!_iconImageView) {
// prevent glitch with marker (cf. https://github.com/airbnb/react-native-maps/issues/738)
UIImageView *empyImageView = [[UIImageView alloc] init];
_iconImageView = empyImageView;
[self iconViewInsertSubview:_iconImageView atIndex:0];
}

_reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
size:self.bounds.size
scale:RCTScreenScale()
clipped:YES
resizeMode:RCTResizeModeCenter
progressBlock:nil
partialLoadBlock:nil
completionBlock:^(NSError *error, UIImage *image) {
if (error) {
// TODO(lmr): do something with the error?
NSLog(@"%@", error);
}
dispatch_async(dispatch_get_main_queue(), ^{

// TODO(gil): This way allows different image sizes
if (_iconImageView) [_iconImageView removeFromSuperview];

// ... but this way is more efficient?
// if (_iconImageView) {
// [_iconImageView setImage:image];
// return;
// }

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

// TODO: w,h or pixel density could be a prop.
float density = 1;
float w = image.size.width/density;
float h = image.size.height/density;
CGRect bounds = CGRectMake(0, 0, w, h);

imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView setFrame:bounds];

// NOTE: sizeToFit doesn't work instead. Not sure why.
// TODO: Doing it this way is not ideal because it causes things to reshuffle
// when the image loads IF the image is larger than the UIView.
// Shouldn't required images have size info automatically via RN?
CGRect selfBounds = unionRect(bounds, self.bounds);
[self setFrame:selfBounds];

_iconImageView = imageView;
[self iconViewInsertSubview:imageView atIndex:0];
});
}];
}

- (void)setTitle:(NSString *)title {
Expand Down
22 changes: 0 additions & 22 deletions lib/ios/AirGoogleMaps/GlobalVars.h

This file was deleted.

54 changes: 0 additions & 54 deletions lib/ios/AirGoogleMaps/GlobalVars.m

This file was deleted.

0 comments on commit 6952e17

Please sign in to comment.