summaryrefslogtreecommitdiff
path: root/platform/ios/test/MGLMapViewContentInsetTests.m
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-10-04 17:13:00 -0700
committerGitHub <noreply@github.com>2019-10-04 17:13:00 -0700
commit5c565a5e51be8379ddc2ffb5c859d8cfebe2fcd5 (patch)
treedcd0ca7902546247d53b9fee402673b16d2a8fd9 /platform/ios/test/MGLMapViewContentInsetTests.m
parent33a70100b839793311ecc73c873c063c7cf65e31 (diff)
downloadqtlocation-mapboxgl-5c565a5e51be8379ddc2ffb5c859d8cfebe2fcd5.tar.gz
[ios] Fixes an issue that caused the ornaments ignore contentInset property. (#15584)
* [ios] Add mapView content inset tests. * [ios] Fix an issue that caused the ornaments ignore the contentInsets. Fixed an issue that caused ornaments ignore the contentInset. Added a new property automaticallyAdjustContentInset that has the same purpose as UIViewController. automaticallyAdjustsScrollViewInsets. This was changed due to the latter being deprecated. * [ios] Fix automaticallyAdjustsScrollViewInsets legacy behavior. The property automaticallyAdjustsScrollViewInsets overrode automaticallyAdjustsScrollViewInsets which caused a breaking change. This is fixed to consider the legacy property when calculating the content insets and added tests for both cases. * [ios] Fix the contentInset value after adding padding to the camera. Fixed an issue that caused a discrepancy between the contentInset in MGLMapView and the padding in the transformation state. When padding is passed through methods such as setCamera it’s persisted. This fix resets the contentInsets. * [ios] Fix pinch test. * [ios] Update automaticallyAdjustsScrollViewInsets name and documentation. * [ios] Update changelog.
Diffstat (limited to 'platform/ios/test/MGLMapViewContentInsetTests.m')
-rw-r--r--platform/ios/test/MGLMapViewContentInsetTests.m177
1 files changed, 177 insertions, 0 deletions
diff --git a/platform/ios/test/MGLMapViewContentInsetTests.m b/platform/ios/test/MGLMapViewContentInsetTests.m
new file mode 100644
index 0000000000..185baf4a05
--- /dev/null
+++ b/platform/ios/test/MGLMapViewContentInsetTests.m
@@ -0,0 +1,177 @@
+#import <Mapbox/Mapbox.h>
+#import <XCTest/XCTest.h>
+
+@interface MGLMapViewContentInsetTests : XCTestCase <MGLMapViewDelegate>
+
+@property (nonatomic) MGLMapView *mapView;
+@property (nonatomic) UIWindow *window;
+@property (nonatomic) UIViewController *viewController;
+@property (nonatomic) XCTestExpectation *styleLoadingExpectation;
+@property (assign) CGRect screenBounds;
+
+@end
+
+@implementation MGLMapViewContentInsetTests
+
+- (void)setUp {
+ [super setUp];
+
+ [MGLAccountManager setAccessToken:@"pk.feedcafedeadbeefbadebede"];
+ NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"];
+ self.screenBounds = UIScreen.mainScreen.bounds;
+ self.mapView = [[MGLMapView alloc] initWithFrame:self.screenBounds styleURL:styleURL];
+ self.mapView.zoomLevel = 16;
+ self.mapView.delegate = self;
+
+ self.viewController = [[UIViewController alloc] init];
+ self.viewController.view = [[UIView alloc] initWithFrame:self.screenBounds];
+ [self.viewController.view addSubview:self.mapView];
+ self.window = [[UIWindow alloc] initWithFrame:self.screenBounds];
+ [self.window addSubview:self.viewController.view];
+ [self.window makeKeyAndVisible];
+
+ if (!self.mapView.style) {
+ _styleLoadingExpectation = [self expectationWithDescription:@"Map view should finish loading style."];
+ [self waitForExpectationsWithTimeout:10 handler:nil];
+ }
+}
+
+- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style {
+ XCTAssertNotNil(mapView.style);
+ XCTAssertEqual(mapView.style, style);
+
+ [_styleLoadingExpectation fulfill];
+}
+
+- (void)tearDown {
+ self.mapView = nil;
+ [MGLAccountManager setAccessToken:nil];
+ [super tearDown];
+}
+
+- (void)testContentInsetCenter {
+ CLLocationCoordinate2D center = CLLocationCoordinate2DMake(1.0, 5.0);
+ self.mapView.centerCoordinate = center;
+ XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.latitude, center.latitude, 0.01);
+ XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.longitude, center.longitude, 0.01);
+
+ CGPoint centerPoint = [self.mapView convertCoordinate:center toPointToView:self.mapView];
+
+ XCTAssertEqualWithAccuracy(centerPoint.x, self.screenBounds.size.width/2, 0.01);
+ XCTAssertEqualWithAccuracy(centerPoint.y, self.screenBounds.size.height/2, 0.01);
+
+ // shifting contentInset should keep the same centerCoordinate but shift the screen
+ // center point accordingly
+ UIEdgeInsets contentInset = UIEdgeInsetsMake(50.0, 10.0, 10.0, 30.0);
+ self.mapView.contentInset = contentInset;
+ XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, contentInset));
+ XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.latitude, center.latitude, 0.01);
+ XCTAssertEqualWithAccuracy(self.mapView.centerCoordinate.longitude, center.longitude, 0.01);
+ CGPoint shiftedPoint = [self.mapView convertCoordinate:center toPointToView:self.mapView];
+ CGPoint expectedShiftedPoint = CGPointMake((self.screenBounds.size.width/2) + ((contentInset.left - contentInset.right) / 2 ),
+ (self.screenBounds.size.height/2) + ((contentInset.top - contentInset.bottom) / 2));
+ XCTAssertEqualWithAccuracy(shiftedPoint.x, expectedShiftedPoint.x, 0.01);
+ XCTAssertEqualWithAccuracy(shiftedPoint.y, expectedShiftedPoint.y, 0.01);
+
+
+}
+
+- (void)testContentInsetOrnaments {
+ CGFloat margin = 8;
+ self.mapView.contentInset = UIEdgeInsetsZero;
+ UIView *scaleBar = self.mapView.scaleBar;
+ CGPoint expectedScaleBarOrigin = CGPointMake(margin, margin);
+ XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin));
+
+ UIView *compassView = self.mapView.compassView;
+ CGFloat x = self.screenBounds.size.width - compassView.bounds.size.width - margin;
+ CGPoint expectedCompassOrigin = CGPointMake(x, margin);
+ XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin));
+
+ UIView *logoView = self.mapView.logoView;
+ CGFloat y = self.screenBounds.size.height - logoView.bounds.size.height - margin;
+ CGPoint expectedLogoOrigin = CGPointMake(margin, y);
+ XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin));
+
+ UIView *attributionView = self.mapView.attributionButton;
+ x = self.screenBounds.size.width - attributionView.bounds.size.width - margin;
+ y = self.screenBounds.size.height - attributionView.bounds.size.height - margin;
+ CGPoint expectedAttributionOrigin = CGPointMake(x, y);
+ XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin));
+
+ UIEdgeInsets insets = UIEdgeInsetsMake(15, 10, 20, 5);
+ self.viewController.automaticallyAdjustsScrollViewInsets = NO;
+ self.mapView.contentInset = insets;
+
+ [self.mapView setNeedsLayout];
+ [self.mapView layoutIfNeeded];
+
+ expectedScaleBarOrigin = CGPointMake(insets.left + self.mapView.scaleBarMargins.x, insets.top + self.mapView.scaleBarMargins.y);
+ XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin));
+
+ x = self.screenBounds.size.width - compassView.bounds.size.width - insets.right - self.mapView.compassViewMargins.x;
+ expectedCompassOrigin = CGPointMake(x, insets.top + self.mapView.compassViewMargins.y);
+ XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin));
+
+ y = self.screenBounds.size.height - logoView.bounds.size.height - insets.bottom - self.mapView.logoViewMargins.y;
+ expectedLogoOrigin = CGPointMake(insets.left + self.mapView.logoViewMargins.x, y);
+ XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin));
+
+ x = self.screenBounds.size.width - attributionView.bounds.size.width - insets.right - self.mapView.attributionButtonMargins.x;
+ y = self.screenBounds.size.height - attributionView.bounds.size.height - insets.bottom - self.mapView.attributionButtonMargins.y;
+ expectedAttributionOrigin = CGPointMake(x, y);
+ XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin));
+
+ // tests that passing negative values result in a 0 inset value
+ insets = UIEdgeInsetsMake(-100, -100, -100, -100);
+ self.mapView.contentInset = insets;
+
+ [self.mapView setNeedsLayout];
+ [self.mapView layoutIfNeeded];
+
+ expectedScaleBarOrigin = CGPointMake(margin, margin);
+ XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin));
+
+ x = self.screenBounds.size.width - compassView.bounds.size.width - margin;
+ expectedCompassOrigin = CGPointMake(x, margin);
+ XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin));
+
+ y = self.screenBounds.size.height - logoView.bounds.size.height - margin;
+ expectedLogoOrigin = CGPointMake(margin, y);
+ XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin));
+
+ x = self.screenBounds.size.width - attributionView.bounds.size.width - margin;
+ y = self.screenBounds.size.height - attributionView.bounds.size.height - margin;
+ expectedAttributionOrigin = CGPointMake(x, y);
+ XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin));
+
+ self.mapView.automaticallyAdjustsContentInset = YES;
+ insets = UIEdgeInsetsMake(100, 100, 100, 100);
+ self.mapView.contentInset = insets;
+ XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, insets));
+
+ [self.mapView setNeedsLayout];
+ [self.mapView layoutIfNeeded];
+
+ // when automaticallyAdjustsContentInset = YES the content insets should be overwriten
+ XCTAssertFalse(UIEdgeInsetsEqualToEdgeInsets(self.mapView.contentInset, insets));
+
+ expectedScaleBarOrigin = CGPointMake(margin, margin);
+ XCTAssertTrue(CGPointEqualToPoint(scaleBar.frame.origin, expectedScaleBarOrigin));
+
+ x = self.screenBounds.size.width - compassView.bounds.size.width - margin;
+ expectedCompassOrigin = CGPointMake(x, margin);
+ XCTAssertTrue(CGPointEqualToPoint(compassView.frame.origin, expectedCompassOrigin));
+
+ y = self.screenBounds.size.height - logoView.bounds.size.height - margin;
+ expectedLogoOrigin = CGPointMake(margin, y);
+ XCTAssertTrue(CGPointEqualToPoint(logoView.frame.origin, expectedLogoOrigin));
+
+ x = self.screenBounds.size.width - attributionView.bounds.size.width - margin;
+ y = self.screenBounds.size.height - attributionView.bounds.size.height - margin;
+ expectedAttributionOrigin = CGPointMake(x, y);
+ XCTAssertTrue(CGPointEqualToPoint(attributionView.frame.origin, expectedAttributionOrigin));
+
+}
+
+@end