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

Fix scalebar ornament triggers unnecessary layoutSubviews #507

Merged
merged 3 commits into from
Oct 15, 2020

Conversation

lloydsheng
Copy link
Contributor

Fix issue #502

@lloydsheng lloydsheng requested a review from a team October 13, 2020 14:03
@lloydsheng lloydsheng linked an issue Oct 13, 2020 that may be closed by this pull request
Copy link
Contributor

@ZiZasaurus ZiZasaurus left a comment

Choose a reason for hiding this comment

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

added log statement to verify that unnecessary layoutSubviews weren't being triggered. Looks good!

Copy link
Contributor

@julianrex julianrex left a comment

Choose a reason for hiding this comment

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

A few questions that can be addressed if appropriate, but otherwise looks good. Thank you!

toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:16];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have an existing constant for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeWidth
multiplier:.5
Copy link
Contributor

Choose a reason for hiding this comment

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

Is half the width of the view essentially the maximum size possible? How does this impact running on iPad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may be a bit long on the iPad, but I think it's acceptable 😂

CGFloat barWidth = totalBarWidth/self.bars.count;

BOOL RTL = [self usesRightToLeftLayout];
CGFloat halfLabelWidth = ceil(self.lastLabelWidth/2);
CGFloat barOffset = RTL ? halfLabelWidth : 0.0;

self.containerView.frame = CGRectMake(barOffset,
intrinsicContentHeight - MGLBarHeight,
CGFloat containerViewX = self.isOnScreenRight ? self.bounds.size.width - totalBarWidth - barOffset : barOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this also need the halfLabelWidth if on the right hand side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs the barOffset(calculated by halfLabelWidth ) for layout direction right to left on either side. Otherwise, labels will display like this 👇
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scalebar ornament triggers layoutSubviews.
4 participants