Skip to content

Commit

Permalink
Merge pull request #193 from hansemannn/TIMOB-23988
Browse files Browse the repository at this point in the history
[TIMOB-23988] iOS: Add click event to "callout" bubble to return infoWindow (Parity)
  • Loading branch information
hansemannn authored Dec 29, 2016
2 parents 33ed4ed + 45580e2 commit e2d06e7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
4 changes: 2 additions & 2 deletions apidoc/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ events:
Note that only one annotation can be selected at any given time.
The `click` event includes a value, `clicksource`, which describes the part of the annotation that was clicked. The `clicksource` can be one of `pin`, `leftButton` or `rightButton` on iOS and pin`, `title`, `subtitle`, `leftPane`, `rightPane`, `infoWindow` or `null` on Android. If the user deselects an annotation
The `click` event includes a value, `clicksource`, which describes the part of the annotation that was clicked. The `clicksource` can be one of `pin`, `infoWindow`, `leftButton` or `rightButton` on iOS and pin`, `title`, `subtitle`, `leftPane`, `rightPane`, `infoWindow` or `null` on Android. If the user deselects an annotation
by clicking on the pin, `clicksource` is `pin`. If the user deselects the
annotation by clicking elsewhere in the map view, `clicksource` is `map`.
Expand All @@ -368,7 +368,7 @@ events:
- name: clicksource
summary: |
Source of the click event. Can be one of `pin`, `leftPane`, `rightPane`, `infoWindow` or `null`.
If it's a shape, it can be one of `polygon`, `polyline`, or `circle`. On android this also applies
If it's a shape, it can be one of `polygon`, `polyline`, or `circle`. On Android, this also applies
for `title` and `subtitle`.
type: String

Expand Down
4 changes: 3 additions & 1 deletion ios/Classes/TiMapAnnotationProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ -(UIView*)makeButton:(id)button tag:(int)buttonTag

-(void)refreshAfterDelay
{
[self performSelector:@selector(refreshIfNeeded) withObject:nil afterDelay:0.1];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
[self refreshIfNeeded];
});
}

-(void)setNeedsRefreshingWithSelection: (BOOL)shouldReselect
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/TiMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
NSMutableArray *polygonProxies;
NSMutableArray *circleProxies;
NSMutableArray *polylineProxies;

//selected annotation
MKAnnotationView<TiMapAnnotation> * selectedAnnotation;

// dictionary for object tracking and association
CFMutableDictionaryRef mapObjects2View; // MKOverlay Object -> MKOverlay Object's renderer
Expand Down
48 changes: 40 additions & 8 deletions ios/Classes/TiMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ -(void)dealloc
CFRelease(mapObjects2View);
mapObjects2View = nil;
}

RELEASE_TO_NIL(locationManager);
RELEASE_TO_NIL(selectedAnnotation);
RELEASE_TO_NIL(locationManager);
RELEASE_TO_NIL(polygonProxies);
RELEASE_TO_NIL(polylineProxies);
RELEASE_TO_NIL(circleProxies);
Expand Down Expand Up @@ -893,21 +893,48 @@ - (TiMapAnnotationProxy*)proxyForAnnotation:(MKAnnotationView*)pinview
return nil;
}

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if ([view conformsToProtocol:@protocol(TiMapAnnotation)])
{
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([view conformsToProtocol:@protocol(TiMapAnnotation)])
{
BOOL isSelected = [view isSelected];
MKAnnotationView<TiMapAnnotation> *ann = (MKAnnotationView<TiMapAnnotation> *)view;

BOOL isSelected = [view isSelected];
MKAnnotationView<TiMapAnnotation> *ann = (MKAnnotationView<TiMapAnnotation> *)view;
[self fireClickEvent:view source:isSelected?@"pin":[ann lastHitName]];
selectedAnnotation = ann;

// If canShowCallout == true we will try to find calloutView to hadleTap on callout
if ([ann canShowCallout]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
[self findCalloutView:ann];
});
}
[self fireClickEvent:view source:isSelected?@"pin":[ann lastHitName]];
}
}

- (void)findCalloutView:(UIView *)node
{
// Dig annotation subviews to find _MKSmallCalloutPassthroughButton
if ([node isKindOfClass:[NSClassFromString(@"_MKSmallCalloutPassthroughButton") class]]) {
// Add tap recogniser to this view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCalloutTap:)];
[node addGestureRecognizer:tap];
} else {
for (UIView *child in node.subviews) {
[self findCalloutView:child];
}
}
}


- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view{
if ([view conformsToProtocol:@protocol(TiMapAnnotation)])
{
BOOL isSelected = [TiUtils boolValue:[view isSelected] def:NO];
MKAnnotationView<TiMapAnnotation> *ann = (MKAnnotationView<TiMapAnnotation> *)view;
if (selectedAnnotation == ann) {
selectedAnnotation = nil;
}
[self fireClickEvent:view source:isSelected ? @"pin" : @"map"];
}
}
Expand Down Expand Up @@ -1079,6 +1106,11 @@ - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

#pragma mark Event generation

-(void)handleCalloutTap:(UIGestureRecognizer *)sender
{
[self fireClickEvent:selectedAnnotation source:@"infoWindow"];
}


-(void)handleLongPressOnMap:(UIGestureRecognizer *)sender
{
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/WildcardGestureRecognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
@implementation WildcardGestureRecognizer
@synthesize touchesBeganCallback;

- (void)dealloc
{
[touchesBeganCallback release];
[super dealloc];
}

-(id)init{
if (self = [super init])
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.8.1
version: 2.8.2
apiversion: 2
architectures: armv7 arm64 i386 x86_64
description: External version of Map module
Expand Down
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 6.0.0.GA
TITANIUM_SDK_VERSION = 6.0.1.GA


//
Expand Down

0 comments on commit e2d06e7

Please sign in to comment.