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 @@ ...@@ -19,7 +19,7 @@
@interface PopoverLabelViewController : UIViewController @interface PopoverLabelViewController : UIViewController
// Init with only a main message shown as the primary label. // 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. // Init with primary string and an attributed string set to secondary text.
- (instancetype)initWithPrimaryAttributedString: - (instancetype)initWithPrimaryAttributedString:
......
...@@ -31,9 +31,6 @@ constexpr CGFloat kVerticalDistance = 24; ...@@ -31,9 +31,6 @@ constexpr CGFloat kVerticalDistance = 24;
// UIScrollView which is used for size calculation. // UIScrollView which is used for size calculation.
@property(nonatomic, strong) UIScrollView* scrollView; @property(nonatomic, strong) UIScrollView* scrollView;
// The main message being presented.
@property(nonatomic, strong, readonly) NSString* message;
// The attributed string being presented as primary text. // The attributed string being presented as primary text.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
NSAttributedString* primaryAttributedString; NSAttributedString* primaryAttributedString;
...@@ -47,13 +44,16 @@ constexpr CGFloat kVerticalDistance = 24; ...@@ -47,13 +44,16 @@ constexpr CGFloat kVerticalDistance = 24;
@implementation PopoverLabelViewController @implementation PopoverLabelViewController
- (instancetype)initWithMessage:(NSString*)message { - (instancetype)initWithMessage:(NSString*)message {
self = [super initWithNibName:nil bundle:nil]; NSDictionary* generalAttributes = @{
if (self) { NSForegroundColorAttributeName : [UIColor colorNamed:kTextPrimaryColor],
_message = message; NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
self.modalPresentationStyle = UIModalPresentationPopover; };
self.popoverPresentationController.delegate = self;
} NSAttributedString* attributedString =
return self; [[NSAttributedString alloc] initWithString:message
attributes:generalAttributes];
return [self initWithPrimaryAttributedString:attributedString
secondaryAttributedString:nil];
} }
- (instancetype)initWithPrimaryAttributedString: - (instancetype)initWithPrimaryAttributedString:
...@@ -107,9 +107,7 @@ constexpr CGFloat kVerticalDistance = 24; ...@@ -107,9 +107,7 @@ constexpr CGFloat kVerticalDistance = 24;
textView.linkTextAttributes = textView.linkTextAttributes =
@{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]}; @{NSForegroundColorAttributeName : [UIColor colorNamed:kBlueColor]};
if (self.message) { if (self.primaryAttributedString) {
textView.text = self.message;
} else if (self.primaryAttributedString) {
textView.attributedText = 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