Skip to content

Commit e652cb7

Browse files
committed
iOS: Refactor code for improved readability and performance
1 parent 50be838 commit e652cb7

File tree

4 files changed

+23
-54
lines changed

4 files changed

+23
-54
lines changed

src/ios/GoogleMaps/MyPluginLayer.m

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -343,30 +343,16 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
343343

344344
// Check other views of other plugins before this plugin
345345
// e.g. PhoneGap-Plugin-ListPicker, etc
346-
UIView *subview;
347-
NSArray *subviews = [self.webView.superview subviews];
348-
//CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
349-
//CGPoint subviewPoint = CGPointMake(browserClickPoint.x, browserClickPoint.y - statusBarFrame.size.height);
350-
351-
for (int i = ((int)[subviews count] - 1); i >= 0; i--) {
352-
subview = [subviews objectAtIndex: i];
353-
//NSLog(@"--->subview[%d] = %@", i, subview);
346+
for (UIView *subview in [self.webView.superview.subviews reverseObjectEnumerator]) {
354347
// we only want to check against other views
355-
if (subview == self.pluginScrollView) {
356-
continue;
357-
}
358-
359-
if (subview.isHidden || !subview.isUserInteractionEnabled) {
360-
continue;
361-
}
348+
if (subview == self.pluginScrollView) continue;
349+
if (subview.isHidden || !subview.isUserInteractionEnabled) continue;
362350

363351
CGPoint subviewPoint = CGPointMake(point.x, point.y - subview.frame.origin.y);
364352
UIView *hit = [subview hitTest:subviewPoint withEvent:event];
365353

366354
if (hit) {
367-
if (subview == self.webView) {
368-
break;
369-
}
355+
if (subview == self.webView) break;
370356
return hit;
371357
}
372358
}
@@ -390,34 +376,23 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
390376
float webviewWidth = self.webView.frame.size.width;
391377
float webviewHeight = self.webView.frame.size.height;
392378

393-
394-
CGRect rect;
395-
NSEnumerator *mapIDs = [self.pluginScrollView.mapCtrls keyEnumerator];
396-
PluginMapViewController *mapCtrl;
397-
id mapId;
398-
NSString *clickedDomId;
399-
400379
CGFloat zoomScale = [[UIScreen mainScreen] scale];
401380
offsetY *= zoomScale;
402381
offsetX *= zoomScale;
403382
webviewWidth *= zoomScale;
404383
webviewHeight *= zoomScale;
405384

406-
NSDictionary *domInfo;
407-
408385
@synchronized(self.pluginScrollView.HTMLNodes) {
409386
//NSLog(@"--->browserClickPoint = %f, %f", browserClickPoint.x, browserClickPoint.y);
410-
clickedDomId = [self findClickedDom:@"root" withPoint:browserClickPoint isMapChild:NO overflow:nil];
387+
NSString *clickedDomId = [self findClickedDom:@"root" withPoint:browserClickPoint isMapChild:NO overflow:nil];
411388
//NSLog(@"--->clickedDomId = %@", clickedDomId);
412389

413-
while(mapId = [mapIDs nextObject]) {
414-
mapCtrl = [self.pluginScrollView.mapCtrls objectForKey:mapId];
415-
if (!mapCtrl.divId) {
416-
continue;
417-
}
418-
domInfo =[self.pluginScrollView.HTMLNodes objectForKey:mapCtrl.divId];
419-
420-
rect = CGRectFromString([domInfo objectForKey:@"size"]);
390+
for (id mapId in [[self.pluginScrollView.mapCtrls keyEnumerator] allObjects]) {
391+
PluginMapViewController *mapCtrl = [self.pluginScrollView.mapCtrls objectForKey:mapId];
392+
if (!mapCtrl.divId) continue;
393+
394+
NSDictionary *domInfo = [self.pluginScrollView.HTMLNodes objectForKey:mapCtrl.divId];
395+
CGRect rect = CGRectFromString([domInfo objectForKey:@"size"]);
421396

422397
// Is the map clickable?
423398
if (mapCtrl.clickable == NO) {

src/ios/GoogleMaps/PluginGroundOverlay.m

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,11 @@ - (void)pluginInitialize
2020
//self.imgCache.totalCostLimit = 3 * 1024 * 1024 * 1024; // 3MB = Cache for image
2121
}
2222

23-
- (void)pluginUnload
24-
{
25-
26-
23+
- (void)pluginUnload {
2724
// Plugin destroy
28-
NSArray *keys = [self.mapCtrl.objects allKeys];
29-
NSString *key;
30-
for (int i = 0; i < [keys count]; i++) {
31-
key = [keys objectAtIndex:i];
25+
for (id key in [self.mapCtrl.objects allKeys]) {
3226
if ([key hasPrefix:@"groundoverlay_property"]) {
33-
key = [key stringByReplacingOccurrencesOfString:@"_property" withString:@""];
34-
GMSGroundOverlay *groundoverlay = (GMSGroundOverlay *)[self.mapCtrl.objects objectForKey:key];
27+
GMSGroundOverlay *groundoverlay = (GMSGroundOverlay *)[self.mapCtrl.objects objectForKey:[key stringByReplacingOccurrencesOfString:@"_property" withString:@""]];
3528
groundoverlay.map = nil;
3629
groundoverlay = nil;
3730
}

src/ios/GoogleMaps/PluginMapViewController.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111
@implementation PluginMapViewController
1212

13-
- (void)mapView:(GMSMapView *)mapView didTapPOIWithPlaceID:(NSString *)placeID name:(NSString *)name location:(CLLocationCoordinate2D)location {
13+
- (void)mapView:(GMSMapView *)mapView
14+
didTapPOIWithPlaceID:(NSString *)placeID
15+
name:(NSString *)name
16+
location:(CLLocationCoordinate2D)location {
1417
NSString* jsName = [name stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
1518
jsName = [jsName stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];
1619
jsName = [jsName stringByReplacingOccurrencesOfString:@"\r" withString:@"\\r"];
17-
18-
NSString* jsString = [NSString
19-
stringWithFormat:@"javascript:if('%@' in plugin.google.maps){plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: ['%@', \"%@\", new plugin.google.maps.LatLng(%f,%f)]});}",
20-
self.overlayId, self.overlayId, @"poi_click", placeID, jsName, location.latitude, location.longitude];
21-
[self execJS:jsString];
20+
21+
[self execJS:[NSString stringWithFormat:@"javascript:if('%@' in plugin.google.maps){plugin.google.maps['%@']({evtName: '%@', callback: '_onMapEvent', args: ['%@', \"%@\", new plugin.google.maps.LatLng(%f,%f)]});}",
22+
self.overlayId, self.overlayId, @"poi_click", placeID, jsName, location.latitude, location.longitude]];
2223
}
2324

2425
/**

src/ios/GoogleMaps/PluginPolygon.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,11 @@ -(void)setGeodesic:(CDVInvokedUrlCommand *)command
696696
[self.mapCtrl.executeQueue addOperationWithBlock:^{
697697
NSString *polygonKey = [command.arguments objectAtIndex:0];
698698
GMSPolygon *polygon = [self.mapCtrl.objects objectForKey:polygonKey];
699-
Boolean isGeodisic = [[command.arguments objectAtIndex:1] boolValue];
699+
Boolean isGeodesic = [[command.arguments objectAtIndex:1] boolValue];
700700

701701
// Apply to the polygon on UI thread.
702702
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
703-
[polygon setGeodesic:isGeodisic];
703+
[polygon setGeodesic:isGeodesic];
704704

705705
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
706706
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

0 commit comments

Comments
 (0)