This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Fix content insets when automaticallyAdjustsScrollViewInsets is set to NO #420
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -886,19 +886,10 @@ - (void)updateConstraintsForOrnament:(UIView *)view | |
NSMutableArray *updatedConstraints = [NSMutableArray array]; | ||
UIEdgeInsets inset = UIEdgeInsetsZero; | ||
|
||
BOOL automaticallyAdjustContentInset; | ||
if (_automaticallyAdjustContentInsetHolder) { | ||
automaticallyAdjustContentInset = _automaticallyAdjustContentInsetHolder.boolValue; | ||
} else { | ||
UIViewController *viewController = [self rootViewController]; | ||
automaticallyAdjustContentInset = viewController.automaticallyAdjustsScrollViewInsets; | ||
} | ||
|
||
|
||
if (! automaticallyAdjustContentInset) { | ||
inset = UIEdgeInsetsMake(self.contentInset.top - self.safeMapViewContentInsets.top, | ||
self.contentInset.left - self.safeMapViewContentInsets.left, | ||
self.contentInset.bottom - self.safeMapViewContentInsets.bottom, | ||
self.contentInset.right - self.safeMapViewContentInsets.right); | ||
if (! [self hasAutomaticallyAdjustContentInset]) { | ||
inset = self.contentInset; | ||
|
||
// makes sure the insets don't have negative values that could hide the ornaments | ||
// thus violating our ToS | ||
|
@@ -910,20 +901,20 @@ - (void)updateConstraintsForOrnament:(UIView *)view | |
|
||
switch (position) { | ||
case MGLOrnamentPositionTopLeft: | ||
[updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:margins.y + inset.top]]; | ||
[updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:margins.x + inset.left]]; | ||
[updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.safeTopAnchor constant:margins.y + inset.top]]; | ||
[updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.safeLeadingAnchor constant:margins.x + inset.left]]; | ||
break; | ||
case MGLOrnamentPositionTopRight: | ||
[updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.mgl_safeTopAnchor constant:margins.y + inset.top]]; | ||
[updatedConstraints addObject:[self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x + inset.right]]; | ||
[updatedConstraints addObject:[view.topAnchor constraintEqualToAnchor:self.safeTopAnchor constant:margins.y + inset.top]]; | ||
[updatedConstraints addObject:[self.safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x + inset.right]]; | ||
break; | ||
case MGLOrnamentPositionBottomLeft: | ||
[updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y + inset.bottom]]; | ||
[updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.mgl_safeLeadingAnchor constant:margins.x + inset.left]]; | ||
[updatedConstraints addObject:[self.safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y + inset.bottom]]; | ||
[updatedConstraints addObject:[view.leadingAnchor constraintEqualToAnchor:self.safeLeadingAnchor constant:margins.x + inset.left]]; | ||
break; | ||
case MGLOrnamentPositionBottomRight: | ||
[updatedConstraints addObject:[self.mgl_safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y + inset.bottom]]; | ||
[updatedConstraints addObject: [self.mgl_safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x + inset.right]]; | ||
[updatedConstraints addObject:[self.safeBottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:margins.y + inset.bottom]]; | ||
[updatedConstraints addObject: [self.safeTrailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margins.x + inset.right]]; | ||
break; | ||
} | ||
|
||
|
@@ -941,10 +932,66 @@ - (void)updateConstraintsForOrnament:(UIView *)view | |
[constraints addObjectsFromArray:updatedConstraints]; | ||
} | ||
|
||
// Convenience method to check if a user has enabled automatically adjust content | ||
// insets. Currently users can use MGLMapView.automaticallyAdjustContentInset or | ||
// UIViewController.automaticallyAdjustsScrollViewInsets | ||
// TODO: Remove when UIViewController.automaticallyAdjustsScrollViewInsets is removed | ||
- (BOOL)hasAutomaticallyAdjustContentInset { | ||
BOOL automaticallyAdjustContentInset; | ||
if (_automaticallyAdjustContentInsetHolder) { | ||
automaticallyAdjustContentInset = _automaticallyAdjustContentInsetHolder.boolValue; | ||
} else { | ||
UIViewController *viewController = [self rootViewController]; | ||
automaticallyAdjustContentInset = viewController.automaticallyAdjustsScrollViewInsets; | ||
} | ||
|
||
return automaticallyAdjustContentInset; | ||
} | ||
|
||
// Checks if it has enabled adjust content insets. When true it will calculate the anchor using | ||
// safe area insets otherwise it will return the map's view anchor. | ||
- (NSLayoutYAxisAnchor *)safeTopAnchor { | ||
if ([self hasAutomaticallyAdjustContentInset]) { | ||
return self.mgl_safeTopAnchor; | ||
} else { | ||
return self.topAnchor; | ||
} | ||
} | ||
Comment on lines
+953
to
+959
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another confusing one for me - is there anyway to combine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What this method is doing is check if it has automatically adjust content insets. If it has then it uses an anchor that considers safe areas which is |
||
|
||
// Checks if it has enabled adjust content insets. When true it will calculate the anchor using | ||
// safe area insets otherwise it will return the map's view anchor. | ||
- (NSLayoutYAxisAnchor *)safeBottomAnchor { | ||
if ([self hasAutomaticallyAdjustContentInset]) { | ||
return self.mgl_safeBottomAnchor; | ||
} else { | ||
return self.bottomAnchor; | ||
} | ||
} | ||
|
||
// Checks if it has enabled adjust content insets. When true it will calculate the anchor using | ||
// safe area insets otherwise it will return the map's view anchor. | ||
- (NSLayoutXAxisAnchor *)safeLeadingAnchor { | ||
if ([self hasAutomaticallyAdjustContentInset]) { | ||
return self.mgl_safeLeadingAnchor; | ||
} else { | ||
return self.leadingAnchor; | ||
} | ||
} | ||
|
||
// Checks if it has enabled adjust content insets. When true it will calculate the anchor using | ||
// safe area insets otherwise it will return the map's view anchor. | ||
- (NSLayoutXAxisAnchor *)safeTrailingAnchor { | ||
if ([self hasAutomaticallyAdjustContentInset]) { | ||
return self.mgl_safeTrailingAnchor; | ||
} else { | ||
return self.trailingAnchor; | ||
} | ||
} | ||
|
||
- (void)installConstraints | ||
{ | ||
[self installCompassViewConstraints]; | ||
[self installScaleBarConstraints]; | ||
[self installCompassViewConstraints]; | ||
[self installLogoViewConstraints]; | ||
[self installAttributionButtonConstraints]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm having trouble understanding the meaning of the method name.
Can we match the similar view controller method?
automaticallyAdjustsContentInsets
depending on context?
EDIT: Oh, I see
- (BOOL)automaticallyAdjustsContentInset
- I'm more confused now 😕There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasAutomaticallyAdjustContentInset
is an internal convenience method to avoid code duplication. Since we have two ways to check if we disabled adjusting automatically content insets: usingUIViewController.automaticallyAdjustsScrollViewInsets
(deprecated) andMGLMapView.automaticallyAdjustContentInset
I am using this method to check these options.