Repository navigation
[ios] Fix the layout constraints on iOS 11 for iPhone X - #10858
Conversation
| constant:8.0 + self.contentInset.bottom]]; | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wpartial-availability" | ||
| [NSLayoutConstraint activateConstraints:@[[safeAreaLayoutGuide.bottomAnchor constraintEqualToSystemSpacingBelowAnchor:self.logoView.bottomAnchor multiplier:1.0]]]; |
There was a problem hiding this comment.
This seems to accomplish the same thing as with compassViewConstraints above, but takes a different approach: activating the new constraint immediately. Is one way better/different than the other?
There was a problem hiding this comment.
Looks like the correct way to add a bottom constraint on iOS 11 is anchor the view to the safeAreaLayoutGuide I was doing the opposite and it was not working.
[safeAreaLayoutGuide.bottomAnchor constraintEqualToSystemSpacingBelowAnchor:self.logoView.bottomAnchor multiplier:1.0]
There was a problem hiding this comment.
Sounds good. However, while we're in this code, can you refactor it to eliminate the duplication? Now that we have a test in place hopefully it feels less risky to do so.
There was a problem hiding this comment.
activating the new constraint immediately
I didn't quite understand - is this necessary @fabian-guerra ?
There was a problem hiding this comment.
This code is no longer valid. Researching the reasons for why the constraint was not applied I tried to force activating the constraint that's why I added this code. If you take a second look you will see that I no longer use this.
|
I agree with #10834 (comment) in that we really need to add tests, otherwise we can’t consider this issue fixed. |
|
@akitchen I bring your test case to this branch and did minor changes to pass the test prior iOS 11. /cc @friedbunny |
akitchen
left a comment
There was a problem hiding this comment.
I'm glad to see you got to the bottom of the issue, but can you take the opportunity to refactor this code to eliminate at least some of the duplicated effort?
| constant:8.0 + self.contentInset.bottom]]; | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wpartial-availability" | ||
| [NSLayoutConstraint activateConstraints:@[[safeAreaLayoutGuide.bottomAnchor constraintEqualToSystemSpacingBelowAnchor:self.logoView.bottomAnchor multiplier:1.0]]]; |
There was a problem hiding this comment.
Sounds good. However, while we're in this code, can you refactor it to eliminate the duplication? Now that we have a test in place hopefully it feels less risky to do so.
| [super tearDown]; | ||
| } | ||
|
|
||
| // TODO: check constraining to superview vs. constraining to safeAreaLayoutGuide.bottomAnchor |
There was a problem hiding this comment.
I think you may have addressed this TODO? I thought we had an issue with layout depending on how the superview was constraining the map view. Please either delete this comment or test both cases (happy to pair on this if it's not clear)
|
|
||
| //compass | ||
| UIImageView *compassView = self.mapView.compassView; | ||
| NSLog(@"================> %@", compassView); |
There was a problem hiding this comment.
Please remove all of the extraneous logging now that we don't need it, as it clutters the already noisy test output.
|
|
||
| CGFloat expectedCompassOriginX = CGRectGetMaxX(self.mapView.bounds) - margin - CGRectGetWidth(compassView.frame); | ||
| CGFloat expectedCompassOriginY = margin; | ||
| // what about width/height? maybe we don't care as much at the moment? |
There was a problem hiding this comment.
Let's either inspect width/height or remove the comment. This was just here as a placeholder while we were defining the test case.
|
Have you considered adding a layer of abstraction on top of the layout API? It would remove a lot of the duplicated code, remove the need for separate code paths for I'm thinking something along these lines: @implementation UIView (MGLAdditions)
- (NSLayoutYAxisAnchor *)safeTopAnchor {
if (@available(iOS 11.0, *)) {
return self.safeAreaLayoutGuide.topAnchor;
} else {
UIViewController *viewController = self.viewControllerForLayoutGuides;
BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets;
if (useLayoutGuides) {
return viewController.topLayoutGuide.bottomAnchor;
} else {
return self.topAnchor;
}
}
}
@end(One additional layer of abstraction is needed to support iOS 8) |
8a79776 to
57faf8c
Compare
|
@frederoni I didn't consider add another level of abstraction tbh. I refactored the code to remove the compiler flags pushing and popping. Since we are using two different APIs for managing the ornaments layout, seems that having two different methods is more clear to read aka |
This is great. Can you take it a bit further while we're here? We require compiling against iOS 11 now, right? So I think we can also remove the code around https://github.com/mapbox/mapbox-gl-native/pull/10858/files#diff-20502b6bc02986a4398d0da84b2d4b94R884 (cc @friedbunny) |
|
On second thought, since we want to cut version 3.7.3 let's get this merged in for the release and log a followup issue for code cleanup related to compile-time version checks. |
friedbunny
left a comment
There was a problem hiding this comment.
This works back to iOS 8 (on sims, at least). 👍
I think the refactors/abstractions that @akitchen and @frederoni have suggested are worth pursuing, but doing that in the future is fine, too.
57faf8c to
13cf3de
Compare
…n_layer_changes * mapbox_release_5.3.2: [android] - rollback fragment flash changes for ViewPager support [android] - update changelog for v5.3.2 [android] - handle null Call instances in HttpRequest [android] - allow setting an OkHttpClient Camera callbacks for velocity animated movements (mapbox#10925) [android] do not overwrite user-set focal point when tracking location (mapbox#10910) [android] - retain configuration for user provided focal point and deselect markers on tap [android] - add filesource activation/deactivation to OfflineRegion status and deletion [android] - check if the render surface has been correctly created before destroying the map [android] - validate zoom level before creating mapbox telem event macos-v0.6.1 [macos] Added dates to changelog [core] update vector-tile dependency to 1.0.1 [ios] Bump podspec to v3.7.3 [ios] Fix the layout constraints on iOS 11 for iPhone X (mapbox#10858)
Fixes #10834