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

[ios] Fix the layout constraints on iOS 11 for iPhone X - #10858

Merged
fabian-guerra merged 9 commits into
release-aguafrom
fabian-map-insets-10834
Jan 10, 2018
Merged

fabian-guerra merged 9 commits into
release-aguafrom
fabian-map-insets-10834

Conversation

@fabian-guerra

Copy link
Copy Markdown
Contributor

Fixes #10834

@fabian-guerra fabian-guerra added the iOS Mapbox Maps SDK for iOS label Jan 8, 2018
@fabian-guerra fabian-guerra added this to the ios-v3.7.3 milestone Jan 8, 2018
@fabian-guerra fabian-guerra self-assigned this Jan 8, 2018
Comment thread platform/ios/src/MGLMapView.mm Outdated
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]]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activating the new constraint immediately

I didn't quite understand - is this necessary @fabian-guerra ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@friedbunny

Copy link
Copy Markdown
Contributor

I agree with #10834 (comment) in that we really need to add tests, otherwise we can’t consider this issue fixed.

@fabian-guerra

Copy link
Copy Markdown
Contributor Author

@akitchen I bring your test case to this branch and did minor changes to pass the test prior iOS 11.

/cc @friedbunny

@akitchen akitchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread platform/ios/src/MGLMapView.mm Outdated
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]]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's either inspect width/height or remove the comment. This was just here as a placeholder while we were defining the test case.

@frederoni

Copy link
Copy Markdown
Contributor

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 -[MGLMapView updateConstraintsPreiOS11] and -[MGLMapView updateConstraints] and avoid the pushing and popping of diagnostic compiler flags.

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)

@fabian-guerra
fabian-guerra force-pushed the fabian-map-insets-10834 branch from 8a79776 to 57faf8c Compare January 10, 2018 17:44
@fabian-guerra

Copy link
Copy Markdown
Contributor Author

@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 -[MGLMapView updateConstraintsPreiOS11] and -[MGLMapView updateConstraints]

@akitchen

Copy link
Copy Markdown
Contributor

I refactored the code to remove the compiler flags pushing and popping.

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)

@akitchen

Copy link
Copy Markdown
Contributor

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 friedbunny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fabian-guerra
fabian-guerra force-pushed the fabian-map-insets-10834 branch from 57faf8c to 13cf3de Compare January 10, 2018 19:25
@fabian-guerra
fabian-guerra merged commit 0542ece into release-agua Jan 10, 2018
@fabian-guerra
fabian-guerra deleted the fabian-map-insets-10834 branch January 10, 2018 20:29
mappy-mobile pushed a commit to Mappy/mapbox-gl-native that referenced this pull request Jan 25, 2018
…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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

iOS Mapbox Maps SDK for iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants