Commit 2835fbc8 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ios] Improve the constructor of PopoverLabelViewController

Having initWithMessage call initWithPrimaryAttributedString:secondaryAttributedString:, so we would have only a single designated initializer and we wouldn't have code duplicated between the two initializers.

Bug: 1094420
Change-Id: Ic1aaf0d7f37e75af5ebe17d6578f44e7acb50f99
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355129Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797971}
parent 6d8956fb
......@@ -19,7 +19,7 @@
@interface PopoverLabelViewController : UIViewController
// Init with only a main message shown as the primary label.
- (instancetype)initWithMessage:(NSString*)message NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithMessage:(NSString*)message;
// Init with primary string and an attributed string set to secondary text.
- (instancetype)initWithPrimaryAttributedString:
......
......@@ -31,9 +31,6 @@ constexpr CGFloat kVerticalDistance = 24;
// UIScrollView which is used for size calculation.
@property(nonatomic, strong) UIScrollView* scrollView;
// The main message being presented.
@property(nonatomic, strong, readonly) NSString* message;
// The attributed string being presented as primary text.
@property(nonatomic, strong, readonly)
NSAttributedString* primaryAttributedString;
......@@ -47,13 +44,16 @@ constexpr CGFloat kVerticalDistance = 24;
@implementation PopoverLabelViewController
- (instancetype)initWithMessage:(NSString*)message {
self = [super initWithNibName:nil bundle:nil];
if (self) {
_message = message;
self.modalPresentationStyle = UIModalPresentationPopover;
self.popoverPresentationController.delegate = self;
}
return self;
NSDictionary* generalAttributes = @{
NSForegroundColorAttributeName : [UIColor colorNamed:kTextPrimaryColor],
NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
};
NSAttributedString* attributedString =
[[NSAttributedString alloc] initWithString:message
attributes:generalAttributes];
return [self initWithPrimaryAttributedString:attributedString
secondaryAttributedString:nil];
}
- (instancetype)initWithPrimaryAttributedString:
......@@ -107,9 +107,7 @@ constexpr CGFloat kVerticalDistance = 24;
textView.linkTextAttributes =
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]};
if (self.message) {
textView.text = self.message;
} else if (self.primaryAttributedString) {
if (self.primaryAttributedString) {
textView.attributedText = self.primaryAttributedString;
}
......
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