This fixes two issues with annotation views that were exposed when dragging them: 1) The annotation view's mapView property was not set until it was moved (in `updateAnnotations:`) so it did not always call its delegate back about the map view delegate dragging methods. This adds a call to set the property when an annotation view is created so the delegate methods are always called. 2) Since the mapView is now always set, a call to the map view's callout view for selected annotation was added to the annotation view drag handler. This forces the callout to close and eliminates an issue where the callout would remain visible as an annotation was dragged away which had the visual effect of a detached callout. To make 2 possible, the map views selected callout view was exposed in the private header.
93 lines
2.8 KiB
Objective-C
93 lines
2.8 KiB
Objective-C
#import <Mapbox/Mapbox.h>
|
|
#import <XCTest/XCTest.h>
|
|
|
|
static NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer";
|
|
|
|
@interface MGLAnnotationView (Test)
|
|
@property (nonatomic) MGLMapView *mapView;
|
|
@property (nonatomic, readwrite) MGLAnnotationViewDragState dragState;
|
|
|
|
- (void)setDragState:(MGLAnnotationViewDragState)dragState;
|
|
@end
|
|
|
|
@interface MGLMapView (Test)
|
|
@property (nonatomic) UIView<MGLCalloutView> *calloutViewForSelectedAnnotation;
|
|
@end
|
|
|
|
@interface MGLTestAnnotation : NSObject <MGLAnnotation>
|
|
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
|
|
@end
|
|
|
|
@implementation MGLTestAnnotation
|
|
@end
|
|
|
|
@interface MGLTestCalloutView: UIView<MGLCalloutView>
|
|
@property (nonatomic) BOOL didCallDismissCalloutAnimated;
|
|
@end
|
|
|
|
@implementation MGLTestCalloutView
|
|
|
|
- (void)dismissCalloutAnimated:(BOOL)animated
|
|
{
|
|
_didCallDismissCalloutAnimated = YES;
|
|
}
|
|
|
|
@end
|
|
|
|
@interface MGLAnnotationViewTests : XCTestCase <MGLMapViewDelegate>
|
|
@property (nonatomic) XCTestExpectation *expectation;
|
|
@property (nonatomic) MGLMapView *mapView;
|
|
@property (nonatomic, weak) MGLAnnotationView *annotationView;
|
|
@end
|
|
|
|
@implementation MGLAnnotationViewTests
|
|
|
|
- (void)setUp
|
|
{
|
|
[super setUp];
|
|
_mapView = [[MGLMapView alloc] initWithFrame:CGRectZero];
|
|
_mapView.delegate = self;
|
|
}
|
|
|
|
- (void)testAnnotationView
|
|
{
|
|
_expectation = [self expectationWithDescription:@"annotation property"];
|
|
|
|
MGLTestAnnotation *annotation = [[MGLTestAnnotation alloc] init];
|
|
[_mapView addAnnotation:annotation];
|
|
|
|
[self waitForExpectationsWithTimeout:1 handler:nil];
|
|
|
|
XCTAssert(_mapView.annotations.count == 1, @"number of annotations should be 1");
|
|
XCTAssertNotNil(_annotationView.annotation, @"annotation property should not be nil");
|
|
XCTAssertNotNil(_annotationView.mapView, @"mapView property should not be nil");
|
|
|
|
MGLTestCalloutView *testCalloutView = [[MGLTestCalloutView alloc] init];
|
|
_mapView.calloutViewForSelectedAnnotation = testCalloutView;
|
|
_annotationView.dragState = MGLAnnotationViewDragStateStarting;
|
|
XCTAssertTrue(testCalloutView.didCallDismissCalloutAnimated, @"callout view was not dismissed");
|
|
|
|
[_mapView removeAnnotation:_annotationView.annotation];
|
|
|
|
XCTAssert(_mapView.annotations.count == 0, @"number of annotations should be 0");
|
|
XCTAssertNil(_annotationView.annotation, @"annotation property should be nil");
|
|
}
|
|
|
|
- (MGLAnnotationView *)mapView:(MGLMapView *)mapView viewForAnnotation:(id<MGLAnnotation>)annotation
|
|
{
|
|
MGLAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:MGLTestAnnotationReuseIdentifer];
|
|
|
|
if (!annotationView)
|
|
{
|
|
annotationView = [[MGLAnnotationView alloc] initWithReuseIdentifier:MGLTestAnnotationReuseIdentifer];
|
|
}
|
|
|
|
_annotationView = annotationView;
|
|
|
|
[_expectation fulfill];
|
|
|
|
return annotationView;
|
|
}
|
|
|
|
@end
|