Skip to content

Commit

Permalink
Add react-native-maps fix react-native-maps#954
Browse files Browse the repository at this point in the history
  • Loading branch information
magrinj committed Jan 17, 2017
1 parent 5d444b8 commit 08565c9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
1 change: 1 addition & 0 deletions ios/AirMaps/AIRMapMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- (BOOL)shouldShowCalloutView;
- (void)showCalloutView;
- (void)hideCalloutView;
- (void)addTapGestureRecognizer;

@end

Expand Down
53 changes: 52 additions & 1 deletion ios/AirMaps/AIRMapMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ - (MKAnnotationView *)getAnnotationView
// In this case, we want to render a platform "default" marker.
if (_pinView == nil) {
_pinView = [[MKPinAnnotationView alloc] initWithAnnotation:self reuseIdentifier: nil];
[self addGestureRecognizerToView:_pinView];
_pinView.annotation = self;
}

Expand Down Expand Up @@ -167,6 +168,56 @@ - (void)showCalloutView
animated:YES];
}

#pragma mark - Tap Gesture & Events.

- (void)addTapGestureRecognizer {
[self addGestureRecognizerToView:nil];
}

- (void)addGestureRecognizerToView:(UIView *)view {
if (!view) {
view = self;
}
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)];
// setting this to NO allows the parent MapView to continue receiving marker selection events
tapGestureRecognizer.cancelsTouchesInView = NO;
[view addGestureRecognizer:tapGestureRecognizer];
}

- (void)_handleTap:(UITapGestureRecognizer *)recognizer {
AIRMapMarker *marker = self;
if (!marker) return;

if (marker.selected) {
CGPoint touchPoint = [recognizer locationInView:marker.map.calloutView];
if ([marker.map.calloutView hitTest:touchPoint withEvent:nil]) {

// the callout got clicked, not the marker
id event = @{
@"action": @"callout-press",
};

if (marker.onCalloutPress) marker.onCalloutPress(event);
if (marker.calloutView && marker.calloutView.onPress) marker.calloutView.onPress(event);
if (marker.map.onCalloutPress) marker.map.onCalloutPress(event);
return;
}
}

// the actual marker got clicked
id event = @{
@"action": @"marker-press",
@"id": marker.identifier ?: @"unknown",
@"coordinate": @{
@"latitude": @(marker.coordinate.latitude),
@"longitude": @(marker.coordinate.longitude)
}
};

if (marker.onPress) marker.onPress(event);
if (marker.map.onMarkerPress) marker.map.onMarkerPress(event);
}

- (void)hideCalloutView
{
// hide the callout view
Expand Down Expand Up @@ -232,7 +283,7 @@ - (void)setImageSrc:(NSString *)imageSrc
- (void)setPinColor:(UIColor *)pinColor
{
_pinColor = pinColor;

if ([_pinView respondsToSelector:@selector(setPinTintColor:)]) {
_pinView.pinTintColor = _pinColor;
}
Expand Down
41 changes: 1 addition & 40 deletions ios/AirMaps/AIRMapMarkerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ @implementation AIRMapMarkerManager
- (UIView *)view
{
AIRMapMarker *marker = [AIRMapMarker new];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)];
// setting this to NO allows the parent MapView to continue receiving marker selection events
tapGestureRecognizer.cancelsTouchesInView = NO;
[marker addGestureRecognizer:tapGestureRecognizer];
[marker addTapGestureRecognizer];
marker.bridge = self.bridge;
return marker;
}
Expand Down Expand Up @@ -78,40 +75,4 @@ - (UIView *)view
}];
}

#pragma mark - Events

- (void)_handleTap:(UITapGestureRecognizer *)recognizer {
AIRMapMarker *marker = (AIRMapMarker *)recognizer.view;
if (!marker) return;

if (marker.selected) {
CGPoint touchPoint = [recognizer locationInView:marker.map.calloutView];
if ([marker.map.calloutView hitTest:touchPoint withEvent:nil]) {

// the callout got clicked, not the marker
id event = @{
@"action": @"callout-press",
};

if (marker.onCalloutPress) marker.onCalloutPress(event);
if (marker.calloutView && marker.calloutView.onPress) marker.calloutView.onPress(event);
if (marker.map.onCalloutPress) marker.map.onCalloutPress(event);
return;
}
}

// the actual marker got clicked
id event = @{
@"action": @"marker-press",
@"id": marker.identifier ?: @"unknown",
@"coordinate": @{
@"latitude": @(marker.coordinate.latitude),
@"longitude": @(marker.coordinate.longitude)
}
};

if (marker.onPress) marker.onPress(event);
if (marker.map.onMarkerPress) marker.map.onMarkerPress(event);
}

@end

0 comments on commit 08565c9

Please sign in to comment.