Commit d104f217 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Fix blank secondary text view issue in PopoverLabelViewController

Previously when passing nil to secondaryAttributedString  while
initiating a PopoverLabelViewController, the popover will show a large
blank area under the primary message. That's because a blank secondary
TextView has occupied the space. Fixed the issue by only create
secondary TextView when secondaryAttributedString has a value.

Bug: 1115925
Change-Id: Ic01ae94037aaae14b76194aca439b3677682b921
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354519
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798627}
parent 435af529
......@@ -113,6 +113,10 @@ constexpr CGFloat kVerticalDistance = 24;
[_scrollView addSubview:textView];
// Only create secondary TextView when |secondaryAttributedString| is not nil.
// Set the constraint accordingly.
if (self.secondaryAttributedString &&
!self.secondaryAttributedString.length) {
UITextView* secondaryTextView = [[UITextView alloc] init];
secondaryTextView.scrollEnabled = NO;
secondaryTextView.editable = NO;
......@@ -125,29 +129,10 @@ constexpr CGFloat kVerticalDistance = 24;
secondaryTextView.textColor = [UIColor colorNamed:kTextSecondaryColor];
secondaryTextView.linkTextAttributes =
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]};
if (self.secondaryAttributedString) {
secondaryTextView.attributedText = self.secondaryAttributedString;
}
[_scrollView addSubview:secondaryTextView];
NSLayoutConstraint* heightConstraint = [_scrollView.heightAnchor
constraintEqualToAnchor:_scrollView.contentLayoutGuide.heightAnchor
multiplier:1];
// UILayoutPriorityDefaultHigh is the default priority for content
// compression. Setting this lower avoids compressing the content of the
// scroll view.
heightConstraint.priority = UILayoutPriorityDefaultHigh - 1;
heightConstraint.active = YES;
CGFloat verticalOffset =
(secondaryTextView.attributedText) ? -kVerticalDistance : 0;
NSLayoutConstraint* verticalConstraint =
[textView.bottomAnchor constraintEqualToAnchor:secondaryTextView.topAnchor
constant:verticalOffset];
[NSLayoutConstraint activateConstraints:@[
[textContainerView.widthAnchor
constraintEqualToAnchor:_scrollView.widthAnchor],
......@@ -163,13 +148,44 @@ constexpr CGFloat kVerticalDistance = 24;
[textContainerView.trailingAnchor
constraintEqualToAnchor:secondaryTextView.trailingAnchor
constant:kHorizontalInsetValue],
verticalConstraint,
[textContainerView.topAnchor constraintEqualToAnchor:textView.topAnchor
[textView.bottomAnchor constraintEqualToAnchor:secondaryTextView.topAnchor
constant:-kVerticalDistance],
[textContainerView.topAnchor
constraintEqualToAnchor:textView.topAnchor
constant:-kVerticalInsetValue],
[textContainerView.bottomAnchor
constraintEqualToAnchor:secondaryTextView.bottomAnchor
constant:kVerticalInsetValue],
]];
} else {
// Constraints used when only have primary TextView.
[NSLayoutConstraint activateConstraints:@[
[textContainerView.widthAnchor
constraintEqualToAnchor:_scrollView.widthAnchor],
[textContainerView.leadingAnchor
constraintEqualToAnchor:textView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:textView.trailingAnchor
constant:kHorizontalInsetValue],
[textContainerView.topAnchor
constraintEqualToAnchor:textView.topAnchor
constant:-kVerticalInsetValue],
[textContainerView.bottomAnchor
constraintEqualToAnchor:textView.bottomAnchor
constant:kVerticalInsetValue],
]];
}
NSLayoutConstraint* heightConstraint = [_scrollView.heightAnchor
constraintEqualToAnchor:_scrollView.contentLayoutGuide.heightAnchor
multiplier:1];
// UILayoutPriorityDefaultHigh is the default priority for content
// compression. Setting this lower avoids compressing the content of the
// scroll view.
heightConstraint.priority = UILayoutPriorityDefaultHigh - 1;
heightConstraint.active = YES;
}
- (void)viewWillAppear:(BOOL)animated {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment