From 3c681237fb45e70ca04517e239ad0bc24d6c8acb Mon Sep 17 00:00:00 2001 From: Jason Wray <jason@mapbox.com> Date: Mon, 28 Mar 2016 14:30:01 -0400 Subject: [PATCH 1/2] [ios] Don't use negative content insets When a map view was smaller than the entire viewport, negative content insets would be applied. Negative content insets would only be valid if the map view extended outside of its frame, which cannot happen. Fixes #4440. --- platform/ios/CHANGELOG.md | 1 + platform/ios/src/MGLMapView.mm | 5 +++++ platform/ios/test/MGLTViewController.h | 1 + platform/ios/test/MGLTViewController.m | 5 +++++ platform/ios/test/MapViewTests.m | 23 +++++++++++++++++++++++ 5 files changed, 35 insertions(+) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 47337546983..68049be4cc7 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -7,6 +7,7 @@ Mapbox welcomes participation and contributions from everyone. If you’d like - If you’ve previously installed the SDK as a static framework, the installation workflow has changed to address issues when submitting your application to the App Store or installing it on a device. Upon upgrading to this version of the SDK, you’ll need to add Mapbox.bundle to the Copy Bundle Resources build phase and remove Mapbox.framework from the Embed Frameworks build phase. ([#4455](https://github.com/mapbox/mapbox-gl-native/pull/4455)) - Offline packs can now be downloaded to allow users to view specific regions of the map offline. A new MGLOfflineStorage class provides APIs for managing MGLOfflinePacks. ([#4221](https://github.com/mapbox/mapbox-gl-native/pull/4221)) - Tiles and other resources are cached in the same file that holds offline resources. The combined cache file is located in a subdirectory of the user’s Application Support directory, which means iOS will not delete the file when disk space runs low. ([#4377](https://github.com/mapbox/mapbox-gl-native/pull/4377)) +- Fixed an issue where the map view’s center would always be calculated as if the view occupied the entire screen. ([#4504](https://github.com/mapbox/mapbox-gl-native/issues/4504)) - The user dot no longer disappears after panning the map across the antimeridian at low zoom levels. ([#4275](https://github.com/mapbox/mapbox-gl-native/pull/4275)) - The map no longer recoils when panning quickly at low zoom levels. ([#4214](https://github.com/mapbox/mapbox-gl-native/pull/4214)) - Fixed an issue causing the map to pan the wrong way when the user pinches unevenly. ([#4427](https://github.com/mapbox/mapbox-gl-native/pull/4427)) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 9b094ec8941..e8165b41e0f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -814,6 +814,11 @@ - (void)adjustContentInset - viewController.bottomLayoutGuide.length); contentInset.bottom = (CGRectGetMaxY(self.bounds) - [self convertPoint:bottomPoint fromView:viewController.view].y); + + // Negative insets are invalid, replace with 0. + contentInset.top = fmaxf(contentInset.top, 0); + contentInset.bottom = fmaxf(contentInset.bottom, 0); + self.contentInset = contentInset; } diff --git a/platform/ios/test/MGLTViewController.h b/platform/ios/test/MGLTViewController.h index 0be0e1ff2c4..349c2160080 100644 --- a/platform/ios/test/MGLTViewController.h +++ b/platform/ios/test/MGLTViewController.h @@ -3,6 +3,7 @@ @interface MGLTViewController : UIViewController - (void)insetMapView; +- (void)tinyMapView; - (void)resetMapView; @end diff --git a/platform/ios/test/MGLTViewController.m b/platform/ios/test/MGLTViewController.m index 09c60bf614f..451dea92929 100644 --- a/platform/ios/test/MGLTViewController.m +++ b/platform/ios/test/MGLTViewController.m @@ -21,6 +21,11 @@ - (void)insetMapView _mapView.frame = CGRectInset(_mapView.frame, 50, 50); } +- (void)tinyMapView +{ + _mapView.frame = CGRectMake(20, self.topLayoutGuide.length, self.view.frame.size.width / 2, self.view.frame.size.height / 2); +} + - (void)resetMapView { _mapView.frame = self.view.bounds; diff --git a/platform/ios/test/MapViewTests.m b/platform/ios/test/MapViewTests.m index 40022a1ee5f..c8fe862e0af 100644 --- a/platform/ios/test/MapViewTests.m +++ b/platform/ios/test/MapViewTests.m @@ -424,6 +424,29 @@ - (void)testInsetMapView { @"compass should lie inside shrunken map view"); } +- (void)testContentInsetsWithTinyMapView { + [tester.viewController tinyMapView]; + [self keyValueObservingExpectationForObject:tester.mapView keyPath:@"contentInset" handler:^BOOL(id observedObject, NSDictionary *change) { + XCTAssertEqual(tester.mapView.contentInset.top, + 0, + @"map should not have top content inset"); + XCTAssertEqual(tester.mapView.contentInset.bottom, + 0, + @"map should not have bottom content inset"); + return YES; + }]; + [self waitForExpectationsWithTimeout:2.0 handler:nil]; + + tester.mapView.frame = CGRectMake(0, 0, tester.mapView.frame.size.width, tester.mapView.frame.size.height); + [self keyValueObservingExpectationForObject:tester.mapView keyPath:@"contentInset" handler:^BOOL(id observedObject, NSDictionary *change) { + XCTAssertEqual(tester.mapView.contentInset.top, + tester.viewController.topLayoutGuide.length, + @"map should have top content inset equal to the top layout guide"); + return YES; + }]; + [self waitForExpectationsWithTimeout:2.0 handler:nil]; +} + - (void)testDelegateRegionWillChange { __block NSUInteger unanimatedCount; __block NSUInteger animatedCount; From 9f24ebd4915f9bceede39c09ea735aa0bae1cebc Mon Sep 17 00:00:00 2001 From: Jason Wray <jason@mapbox.com> Date: Mon, 28 Mar 2016 15:42:14 -0400 Subject: [PATCH 2/2] [ios] Make showAnnotations default padding proportional at smaller frame sizes --- platform/ios/src/MGLMapView.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index e8165b41e0f..b7fc9b9a35c 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2969,9 +2969,9 @@ - (void)deselectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animate - (void)showAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations animated:(BOOL)animated { - CGFloat defaultPadding = 100; - CGFloat yPadding = (self.frame.size.height / 2 <= defaultPadding) ? (self.frame.size.height / 5) : defaultPadding; - CGFloat xPadding = (self.frame.size.width / 2 <= defaultPadding) ? (self.frame.size.width / 5) : defaultPadding; + CGFloat maximumPadding = 100; + CGFloat yPadding = (self.frame.size.height / 5 <= maximumPadding) ? (self.frame.size.height / 5) : maximumPadding; + CGFloat xPadding = (self.frame.size.width / 5 <= maximumPadding) ? (self.frame.size.width / 5) : maximumPadding; UIEdgeInsets edgeInsets = UIEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding);