Skip to content
Permalink
Browse files

Weak refs to gesture targets (#2818)

  • Loading branch information...
ukrbublik authored and christopherdro committed Apr 17, 2019
1 parent 90e4a6e commit 55a28792941c84c578ace632d787aef8aed27c3a
Showing with 15 additions and 9 deletions.
  1. +15 −9 lib/ios/AirGoogleMaps/AIRGoogleMap.m
@@ -52,6 +52,8 @@ @interface AIRGoogleMap ()

- (id)eventFromCoordinate:(CLLocationCoordinate2D)coordinate;

@property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSDictionary*> *origGestureRecognizersMeta;

@end

@implementation AIRGoogleMap
@@ -62,7 +64,6 @@ @implementation AIRGoogleMap
BOOL _initialCameraSetOnLoad;
BOOL _didCallOnMapReady;
BOOL _didMoveToWindow;
NSMutableDictionary<NSNumber *, NSDictionary*> *_origGestureRecognizersMeta;
BOOL _zoomTapEnabled;
}

@@ -91,7 +92,7 @@ - (instancetype)init
options:NSKeyValueObservingOptionNew
context:NULL];

_origGestureRecognizersMeta = [[NSMutableDictionary alloc] init];
self.origGestureRecognizersMeta = [[NSMutableDictionary alloc] init];
}
return self;
}
@@ -629,7 +630,7 @@ -(void)overrideGestureRecognizersForView:(UIView*)view {
NSArray* grs = view.gestureRecognizers;
for (UIGestureRecognizer* gestureRecognizer in grs) {
NSNumber* grHash = [NSNumber numberWithUnsignedInteger:gestureRecognizer.hash];
if([_origGestureRecognizersMeta objectForKey:grHash] != nil)
if([self.origGestureRecognizersMeta objectForKey:grHash] != nil)
continue; //already patched

//get original handlers
@@ -640,7 +641,10 @@ -(void)overrideGestureRecognizersForView:(UIView*)view {
NSObject* target = [trg valueForKey:@"target"];
SEL action = [self getActionForTarget:trg];
isZoomTapGesture = [NSStringFromSelector(action) isEqualToString:@"handleZoomTapGesture:"];
[origTargetsActions addObject:@{@"target": target, @"action": NSStringFromSelector(action)}];
[origTargetsActions addObject:@{
@"target": [NSValue valueWithNonretainedObject:target],
@"action": NSStringFromSelector(action)
}];
}
if (isZoomTapGesture && self.zoomTapEnabled == NO) {
[view removeGestureRecognizer:gestureRecognizer];
@@ -649,15 +653,16 @@ -(void)overrideGestureRecognizersForView:(UIView*)view {

//replace with extendedMapGestureHandler
for (NSDictionary* origTargetAction in origTargetsActions) {
NSObject* target = [origTargetAction objectForKey:@"target"];
NSValue* targetValue = [origTargetAction objectForKey:@"target"];
NSObject* target = [targetValue nonretainedObjectValue];
NSString* actionString = [origTargetAction objectForKey:@"action"];
SEL action = NSSelectorFromString(actionString);
[gestureRecognizer removeTarget:target action:action];
}
[gestureRecognizer addTarget:self action:@selector(extendedMapGestureHandler:)];

[_origGestureRecognizersMeta setObject:@{@"targets": origTargetsActions}
forKey:grHash];
[self.origGestureRecognizersMeta setObject:@{@"targets": origTargetsActions}
forKey:grHash];
}
}

@@ -735,10 +740,11 @@ - (id)extendedMapGestureHandler:(UIGestureRecognizer*)gestureRecognizer {
}

if (performOriginalActions) {
NSDictionary* origMeta = [_origGestureRecognizersMeta objectForKey:grHash];
NSDictionary* origMeta = [self.origGestureRecognizersMeta objectForKey:grHash];
NSDictionary* origTargets = [origMeta objectForKey:@"targets"];
for (NSDictionary* origTarget in origTargets) {
NSObject* target = [origTarget objectForKey:@"target"];
NSValue* targetValue = [origTarget objectForKey:@"target"];
NSObject* target = [targetValue nonretainedObjectValue];
NSString* actionString = [origTarget objectForKey:@"action"];
SEL action = NSSelectorFromString(actionString);
#pragma clang diagnostic push

0 comments on commit 55a2879

Please sign in to comment.
You can’t perform that action at this time.