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,24 +113,69 @@ constexpr CGFloat kVerticalDistance = 24; ...@@ -113,24 +113,69 @@ constexpr CGFloat kVerticalDistance = 24;
[_scrollView addSubview:textView]; [_scrollView addSubview:textView];
UITextView* secondaryTextView = [[UITextView alloc] init]; // Only create secondary TextView when |secondaryAttributedString| is not nil.
secondaryTextView.scrollEnabled = NO; // Set the constraint accordingly.
secondaryTextView.editable = NO; if (self.secondaryAttributedString &&
secondaryTextView.delegate = self; !self.secondaryAttributedString.length) {
secondaryTextView.backgroundColor = [UIColor clearColor]; UITextView* secondaryTextView = [[UITextView alloc] init];
secondaryTextView.font = secondaryTextView.scrollEnabled = NO;
[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]; secondaryTextView.editable = NO;
secondaryTextView.adjustsFontForContentSizeCategory = YES; secondaryTextView.delegate = self;
secondaryTextView.translatesAutoresizingMaskIntoConstraints = NO; secondaryTextView.backgroundColor = [UIColor clearColor];
secondaryTextView.textColor = [UIColor colorNamed:kTextSecondaryColor]; secondaryTextView.font =
secondaryTextView.linkTextAttributes = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]}; secondaryTextView.adjustsFontForContentSizeCategory = YES;
secondaryTextView.translatesAutoresizingMaskIntoConstraints = NO;
if (self.secondaryAttributedString) { secondaryTextView.textColor = [UIColor colorNamed:kTextSecondaryColor];
secondaryTextView.linkTextAttributes =
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]};
secondaryTextView.attributedText = self.secondaryAttributedString; secondaryTextView.attributedText = self.secondaryAttributedString;
}
[_scrollView addSubview:secondaryTextView]; [_scrollView addSubview:secondaryTextView];
[NSLayoutConstraint activateConstraints:@[
[textContainerView.widthAnchor
constraintEqualToAnchor:_scrollView.widthAnchor],
[textContainerView.leadingAnchor
constraintEqualToAnchor:textView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.leadingAnchor
constraintEqualToAnchor:secondaryTextView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:textView.trailingAnchor
constant:kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:secondaryTextView.trailingAnchor
constant:kHorizontalInsetValue],
[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 NSLayoutConstraint* heightConstraint = [_scrollView.heightAnchor
constraintEqualToAnchor:_scrollView.contentLayoutGuide.heightAnchor constraintEqualToAnchor:_scrollView.contentLayoutGuide.heightAnchor
...@@ -141,35 +186,6 @@ constexpr CGFloat kVerticalDistance = 24; ...@@ -141,35 +186,6 @@ constexpr CGFloat kVerticalDistance = 24;
// scroll view. // scroll view.
heightConstraint.priority = UILayoutPriorityDefaultHigh - 1; heightConstraint.priority = UILayoutPriorityDefaultHigh - 1;
heightConstraint.active = YES; 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],
[textContainerView.leadingAnchor
constraintEqualToAnchor:textView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.leadingAnchor
constraintEqualToAnchor:secondaryTextView.leadingAnchor
constant:-kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:textView.trailingAnchor
constant:kHorizontalInsetValue],
[textContainerView.trailingAnchor
constraintEqualToAnchor:secondaryTextView.trailingAnchor
constant:kHorizontalInsetValue],
verticalConstraint,
[textContainerView.topAnchor constraintEqualToAnchor:textView.topAnchor
constant:-kVerticalInsetValue],
[textContainerView.bottomAnchor
constraintEqualToAnchor:secondaryTextView.bottomAnchor
constant:kVerticalInsetValue],
]];
} }
- (void)viewWillAppear:(BOOL)animated { - (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