Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Don't use negative content insets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
friedbunny committed Mar 29, 2016
1 parent 13882a3 commit 183f55e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Mapbox welcomes participation and contributions from everyone. If you’d like
- The Improve This Map tool now uses the same zoom level that is currently being shown in the map view. ([#4068](https://github.com/mapbox/mapbox-gl-native/pull/4068))
- Fixed a formatting issue in the documentation for `MGLCoordinateBoundsIsEmpty()`. ([#3958](https://github.com/mapbox/mapbox-gl-native/pull/3958))
- Fixed issues with configuration and documentation that caused problems when installing apps built with the static binary to devices. This change also fixed App Store submission problems when uploading an app built with the static binary. ([#4455](https://github.com/mapbox/mapbox-gl-native/pull/4455))
- 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))

## 3.1.2

Expand Down
5 changes: 5 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions platform/ios/test/MGLTViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@interface MGLTViewController : UIViewController

- (void)insetMapView;
- (void)tinyMapView;
- (void)resetMapView;

@end
5 changes: 5 additions & 0 deletions platform/ios/test/MGLTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions platform/ios/test/MapViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:5.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:5.0 handler:nil];
}

- (void)testDelegateRegionWillChange {
__block NSUInteger unanimatedCount;
__block NSUInteger animatedCount;
Expand Down

0 comments on commit 183f55e

Please sign in to comment.