Commit 4eccb972 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Move Reading List attributed text logic to utility functions.

This will allow the icon insertion logic to be shared across different
implementations of the Reading List empty state.

Bug: 851962
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ibd4abe71be34ae019786620ba88ba6f226b75456
Reviewed-on: https://chromium-review.googlesource.com/1135983
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575017}
parent 899d4811
...@@ -1160,6 +1160,9 @@ Handoff must also be enabled in the General section of Settings, and your device ...@@ -1160,6 +1160,9 @@ Handoff must also be enabled in the General section of Settings, and your device
Edit Edit
</message> </message>
<message name="IDS_IOS_READING_LIST_EMPTY_MESSAGE" desc="Message to explain to the user how to add entries to the reading list" meaning="[Length: unlimited]"> <message name="IDS_IOS_READING_LIST_EMPTY_MESSAGE" desc="Message to explain to the user how to add entries to the reading list" meaning="[Length: unlimited]">
Your reading list is available offline. To add a page to your reading list, tap <ph name="SHARE_OPENING_ICON">SHARE_OPENING_ICON<ex>(menu icon)</ex></ph> then <ph name="READ_LATER_TEXT">READ_LATER_TEXT<ex>Read Later</ex></ph>.
</message>
<message name="IDS_IOS_READING_LIST_EMPTY_MESSAGE_LEGACY" desc="Message to explain to the user how to add entries to the reading list" meaning="[Length: unlimited]">
Your reading list is available offline. To add a page to your reading list, tap <ph name="SHARE_OPENING_ICON">SHARE_OPENING_ICON<ex>Menu > Share > Read Later</ex></ph>. Your reading list is available offline. To add a page to your reading list, tap <ph name="SHARE_OPENING_ICON">SHARE_OPENING_ICON<ex>Menu > Share > Read Later</ex></ph>.
</message> </message>
<message name="IDS_IOS_READING_LIST_JUST_NOW" desc="String indicating that an event (adding item, distillation) happened less than one minute ago. [Length: 25em]"> <message name="IDS_IOS_READING_LIST_JUST_NOW" desc="String indicating that an event (adding item, distillation) happened less than one minute ago. [Length: 25em]">
......
...@@ -77,6 +77,8 @@ source_set("reading_list_ui") { ...@@ -77,6 +77,8 @@ source_set("reading_list_ui") {
sources = [ sources = [
"empty_reading_list_background_view.h", "empty_reading_list_background_view.h",
"empty_reading_list_background_view.mm", "empty_reading_list_background_view.mm",
"empty_reading_list_message_util.h",
"empty_reading_list_message_util.mm",
"legacy_reading_list_toolbar.h", "legacy_reading_list_toolbar.h",
"legacy_reading_list_toolbar.mm", "legacy_reading_list_toolbar.mm",
"legacy_reading_list_toolbar_button.h", "legacy_reading_list_toolbar_button.h",
...@@ -108,9 +110,11 @@ source_set("reading_list_ui") { ...@@ -108,9 +110,11 @@ source_set("reading_list_ui") {
"resources:distillation_fail", "resources:distillation_fail",
"resources:distillation_success", "resources:distillation_success",
"resources:reading_list_empty_state", "resources:reading_list_empty_state",
"resources:reading_list_empty_state_new",
"resources:reading_list_share_icon", "resources:reading_list_share_icon",
"resources:reading_list_side_swipe", "resources:reading_list_side_swipe",
"resources:reading_list_toolbar_icon", "resources:reading_list_toolbar_icon",
"resources:reading_list_tools_icon",
"//base", "//base",
"//base:i18n", "//base:i18n",
"//components/strings", "//components/strings",
......
...@@ -5,60 +5,31 @@ ...@@ -5,60 +5,31 @@
#import "ios/chrome/browser/ui/reading_list/empty_reading_list_background_view.h" #import "ios/chrome/browser/ui/reading_list/empty_reading_list_background_view.h"
#include "base/logging.h" #include "base/logging.h"
#include "ios/chrome/browser/ui/rtl_geometry.h" #import "ios/chrome/browser/ui/reading_list/empty_reading_list_message_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace { namespace {
// Images name. // Images name.
NSString* const kEmptyReadingListBackgroundIcon = @"reading_list_empty_state"; NSString* const kEmptyReadingListBackgroundIcon = @"reading_list_empty_state";
NSString* const kToolbarMenuIcon = @"reading_list_toolbar_icon";
NSString* const kShareMenuIcon = @"reading_list_share_icon";
// Tag in string.
NSString* const kOpenShareMarker = @"SHARE_OPENING_ICON";
// Background view constants. // Background view constants.
const CGFloat kTextImageSpacing = 10;
const CGFloat kTextHorizontalMinimumMargin = 32;
const CGFloat kTextMaximalWidth = 255;
const CGFloat kImageWidth = 60;
const CGFloat kImageHeight = 44; const CGFloat kImageHeight = 44;
const CGFloat kFontSize = 16; const CGFloat kImageWidth = 60;
const CGFloat kIconHeight = 24;
const CGFloat kToolbarMenuWidth = 18;
const CGFloat kShareMenuWidth = 24;
const CGFloat kLineHeight = 24;
const CGFloat kPercentageFromTopForPosition = 0.4; const CGFloat kPercentageFromTopForPosition = 0.4;
const CGFloat kTextHorizontalMinimumMargin = 32;
const CGFloat kTextImageSpacing = 10;
const CGFloat kTextMaximalWidth = 255;
} // namespace } // namespace
@interface EmptyReadingListBackgroundView () @interface EmptyReadingListBackgroundView ()
// Attaches the icon named |iconName| to |instructionString| and a |caret|. The
// icon is positionned using the |iconOffset| and with the |attributes| (mainly
// the color). |spaceBeforeCaret| controls whether a space should be added
// between the image and the caret.
- (void)attachIconNamed:(NSString*)iconName
toString:(NSMutableAttributedString*)instructionString
withCaret:(NSMutableAttributedString*)caret
offset:(CGFloat)iconOffset
width:(CGFloat)icondWidth
imageAttributes:(NSDictionary*)attributes;
// Sets the constraints for this view, positionning the |imageView| in the X // Sets the constraints for this view, positionning the |imageView| in the X
// center and at 40% of the top. The |label| is positionned below. // center and at 40% of the top. The |label| is positionned below.
- (void)setConstraintsToImageView:(UIImageView*)imageView - (void)setConstraintsToImageView:(UIImageView*)imageView
andLabel:(UILabel*)label; andLabel:(UILabel*)label;
// Returns the caret string to be displayed.
- (NSString*)caretString;
@end @end
...@@ -69,111 +40,13 @@ const CGFloat kPercentageFromTopForPosition = 0.4; ...@@ -69,111 +40,13 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
- (instancetype)init { - (instancetype)init {
self = [super initWithFrame:CGRectZero]; self = [super initWithFrame:CGRectZero];
if (self) { if (self) {
NSString* rawText =
l10n_util::GetNSString(IDS_IOS_READING_LIST_EMPTY_MESSAGE);
// Add two spaces between Read Later and the preceding caret.
NSString* readLater = [@" "
stringByAppendingString:l10n_util::GetNSString(
IDS_IOS_SHARE_MENU_READING_LIST_ACTION)];
id<MDCTypographyFontLoading> fontLoader = [MDCTypography fontLoader];
UIColor* textColor = [[MDCPalette greyPalette] tint700];
UIFont* textFont = [fontLoader regularFontOfSize:kFontSize];
NSMutableParagraphStyle* paragraphStyle =
[[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = kLineHeight - textFont.lineHeight;
NSDictionary* textAttributes = @{
NSFontAttributeName : textFont,
NSForegroundColorAttributeName : textColor,
NSParagraphStyleAttributeName : paragraphStyle
};
// Offset to vertically center the icons.
CGFloat iconOffset = (textFont.xHeight - kIconHeight) / 2.0;
UIFont* instructionFont = [fontLoader boldFontOfSize:kFontSize];
NSDictionary* instructionAttributes = @{
NSFontAttributeName : instructionFont,
NSForegroundColorAttributeName : textColor,
};
NSMutableAttributedString* baseAttributedString =
[[NSMutableAttributedString alloc] initWithString:rawText
attributes:textAttributes];
NSMutableAttributedString* caret = [[NSMutableAttributedString alloc]
initWithString:[self caretString]
attributes:instructionAttributes];
NSMutableAttributedString* instructionString =
[[NSMutableAttributedString alloc] init];
NSString* accessibilityInstructionString = @":";
// Add the images inside the string.
if (IsCompactWidth() || !IsIPadIdiom()) {
// TODO(crbug.com/698726): When the share icon is displayed in the toolbar
// for landscape iPhone 6+, remove !IsIPadIdiom().
// If the device has a compact display the share menu is accessed from the
// toolbar menu. If it is expanded, the share menu is directly accessible.
[self attachIconNamed:kToolbarMenuIcon
toString:instructionString
withCaret:caret
offset:iconOffset
width:kToolbarMenuWidth
imageAttributes:textAttributes];
accessibilityInstructionString = [[accessibilityInstructionString
stringByAppendingString:l10n_util::GetNSString(
IDS_IOS_TOOLBAR_SETTINGS)]
stringByAppendingString:@", "];
// Add a space before the share icon.
[instructionString
appendAttributedString:[[NSAttributedString alloc]
initWithString:@" "
attributes:instructionAttributes]];
}
[self attachIconNamed:kShareMenuIcon
toString:instructionString
withCaret:caret
offset:iconOffset
width:kShareMenuWidth
imageAttributes:textAttributes];
accessibilityInstructionString = [[accessibilityInstructionString
stringByAppendingString:l10n_util::GetNSString(
IDS_IOS_TOOLS_MENU_SHARE)]
stringByAppendingString:@", "];
// Add the "Read Later" string.
NSAttributedString* shareMenuAction =
[[NSAttributedString alloc] initWithString:readLater
attributes:instructionAttributes];
[instructionString appendAttributedString:shareMenuAction];
accessibilityInstructionString =
[accessibilityInstructionString stringByAppendingString:readLater];
// Marker
NSRange iconRange =
[[baseAttributedString string] rangeOfString:kOpenShareMarker];
DCHECK(iconRange.location != NSNotFound);
[baseAttributedString replaceCharactersInRange:iconRange
withAttributedString:instructionString];
NSString* accessibilityLabel =
l10n_util::GetNSString(IDS_IOS_READING_LIST_EMPTY_MESSAGE);
accessibilityLabel = [accessibilityLabel
stringByReplacingOccurrencesOfString:kOpenShareMarker
withString:accessibilityInstructionString];
// Attach to the label. // Attach to the label.
UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero]; UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero];
label.attributedText = baseAttributedString; label.attributedText = GetReadingListEmptyMessage();
label.numberOfLines = 0; label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter; label.textAlignment = NSTextAlignmentCenter;
label.accessibilityLabel = accessibilityLabel; label.accessibilityLabel = GetReadingListEmptyMessageA11yLabel();
label.accessibilityIdentifier = label.accessibilityIdentifier =
[EmptyReadingListBackgroundView accessibilityIdentifier]; [EmptyReadingListBackgroundView accessibilityIdentifier];
[label setTranslatesAutoresizingMaskIntoConstraints:NO]; [label setTranslatesAutoresizingMaskIntoConstraints:NO];
...@@ -195,39 +68,13 @@ const CGFloat kPercentageFromTopForPosition = 0.4; ...@@ -195,39 +68,13 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
#pragma mark - Private #pragma mark - Private
- (void)attachIconNamed:(NSString*)iconName
toString:(NSMutableAttributedString*)instructionString
withCaret:(NSMutableAttributedString*)caret
offset:(CGFloat)iconOffset
width:(CGFloat)iconWidth
imageAttributes:(NSDictionary*)attributes {
// Add a zero width space to set the attributes for the image.
[instructionString appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\u200B"
attributes:attributes]];
NSTextAttachment* toolbarIcon = [[NSTextAttachment alloc] init];
toolbarIcon.image = [[UIImage imageNamed:iconName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
toolbarIcon.bounds = CGRectMake(0, iconOffset, iconWidth, kIconHeight);
[instructionString
appendAttributedString:[NSAttributedString
attributedStringWithAttachment:toolbarIcon]];
[instructionString appendAttributedString:[[NSAttributedString alloc]
initWithString:@" "
attributes:attributes]];
[instructionString appendAttributedString:caret];
}
- (void)setConstraintsToImageView:(UIImageView*)imageView - (void)setConstraintsToImageView:(UIImageView*)imageView
andLabel:(UILabel*)label { andLabel:(UILabel*)label {
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[[imageView heightAnchor] constraintEqualToConstant:kImageHeight], [imageView.heightAnchor constraintEqualToConstant:kImageHeight],
[[imageView widthAnchor] constraintEqualToConstant:kImageWidth], [imageView.widthAnchor constraintEqualToConstant:kImageWidth],
[[self centerXAnchor] constraintEqualToAnchor:label.centerXAnchor], [self.centerXAnchor constraintEqualToAnchor:label.centerXAnchor],
[[self centerXAnchor] constraintEqualToAnchor:imageView.centerXAnchor], [self.centerXAnchor constraintEqualToAnchor:imageView.centerXAnchor],
[label.topAnchor constraintEqualToAnchor:imageView.bottomAnchor [label.topAnchor constraintEqualToAnchor:imageView.bottomAnchor
constant:kTextImageSpacing], constant:kTextImageSpacing],
[label.trailingAnchor [label.trailingAnchor
...@@ -255,10 +102,4 @@ const CGFloat kPercentageFromTopForPosition = 0.4; ...@@ -255,10 +102,4 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
[self addConstraints:@[ verticalAlignment ]]; [self addConstraints:@[ verticalAlignment ]];
} }
- (NSString*)caretString {
if (UseRTLLayout())
return @"\u25C2";
return @"\u25B8";
}
@end @end
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_READING_LIST_EMPTY_READING_LIST_MESSAGE_UTIL_H_
#define IOS_CHROME_BROWSER_UI_READING_LIST_EMPTY_READING_LIST_MESSAGE_UTIL_H_
#import <UIKit/UIKit.h>
// Returns the attributed message to use for the empty Reading List background
// view.
NSAttributedString* GetReadingListEmptyMessage();
// Returns the accessibility label to use for the label displaying the text
// returned by GetReadingListEmptyMessage().
NSString* GetReadingListEmptyMessageA11yLabel();
#endif // IOS_CHROME_BROWSER_UI_READING_LIST_EMPTY_READING_LIST_MESSAGE_UTIL_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/reading_list/empty_reading_list_message_util.h"
#include "base/logging.h"
#include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Images name.
NSString* const kToolsIcon = @"reading_list_tools_icon";
NSString* const kToolsIconLegacy = @"reading_list_toolbar_icon";
NSString* const kShareIconLegacy = @"reading_list_share_icon";
// Tag in string.
NSString* const kOpenShareMarker = @"SHARE_OPENING_ICON";
NSString* const kReadLaterTextMarker = @"READ_LATER_TEXT";
// Background view constants.
const CGFloat kFontSize = 16;
const CGFloat kLineHeight = 24;
// Enum type describing the icons used by the attributed empty table message.
enum class IconType { TOOLS, SHARE };
// Returns the UIImage corresponding with |icon_type|.
UIImage* GetIconWithType(IconType icon_type) {
if (experimental_flags::IsReadingListUIRebootEnabled()) {
switch (icon_type) {
case IconType::TOOLS:
return [UIImage imageNamed:kToolsIcon];
case IconType::SHARE:
NOTREACHED() << "The share icon is not used in the UI refresh.";
return nil;
}
} else {
switch (icon_type) {
case IconType::TOOLS:
return [UIImage imageNamed:kToolsIconLegacy];
case IconType::SHARE:
return [UIImage imageNamed:kShareIconLegacy];
}
}
}
// Returns the font to use for the message text.
UIFont* GetMessageFont() {
return experimental_flags::IsReadingListUIRebootEnabled()
? [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
: [[MDCTypography fontLoader] regularFontOfSize:kFontSize];
}
// Returns the attributes to use for the message text.
NSMutableDictionary* GetMessageAttributes() {
NSMutableDictionary* attributes = [NSMutableDictionary dictionary];
UIFont* font = GetMessageFont();
attributes[NSFontAttributeName] = font;
attributes[NSForegroundColorAttributeName] =
experimental_flags::IsReadingListUIRebootEnabled()
? [UIColor grayColor]
: [[MDCPalette greyPalette] tint700];
NSMutableParagraphStyle* paragraph_style =
[[NSMutableParagraphStyle alloc] init];
paragraph_style.lineBreakMode = NSLineBreakByWordWrapping;
paragraph_style.alignment = NSTextAlignmentCenter;
// If the line wrapping occurs that one of the icons is the first character on
// a new line, the default line spacing will result in uneven line heights.
// Manually setting the line spacing here prevents that from occurring.
paragraph_style.lineSpacing = kLineHeight - font.lineHeight;
attributes[NSParagraphStyleAttributeName] = paragraph_style;
return attributes;
}
// Returns the attributes to use for the instructions on how to reach the "Read
// Later" option.
NSMutableDictionary* GetInstructionAttributes() {
NSMutableDictionary* attributes = GetMessageAttributes();
attributes[NSFontAttributeName] =
experimental_flags::IsReadingListUIRebootEnabled()
? [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
: [[MDCTypography fontLoader] boldFontOfSize:kFontSize];
return attributes;
}
// Returns the "Read Later" text to appear at the end of the string, with
// correct styling.
NSAttributedString* GetReadLaterString() {
NSString* read_later_text =
l10n_util::GetNSString(experimental_flags::IsReadingListUIRebootEnabled()
? IDS_IOS_SHARE_MENU_READING_LIST_ACTION
: IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST);
return [[NSAttributedString alloc] initWithString:read_later_text
attributes:GetInstructionAttributes()];
}
// Appends the icon with |icon_type| to |text|. Spacer text that is added by
// this function is formatted with |attributes|.
void AppendIcon(IconType icon_type,
NSMutableAttributedString* text,
NSDictionary* attributes) {
// Add a zero width space to set the attributes for the image.
NSAttributedString* spacer =
[[NSAttributedString alloc] initWithString:@"\u200B"
attributes:attributes];
[text appendAttributedString:spacer];
// The icon bounds must be offset to be vertically centered with the message
// text.
UIImage* icon = GetIconWithType(icon_type);
CGRect icon_bounds = CGRectZero;
icon_bounds.size = icon.size;
icon_bounds.origin.y = (GetMessageFont().xHeight - icon.size.height) / 2.0;
// Attach the icon image.
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
attachment.image =
[icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
attachment.bounds = icon_bounds;
NSAttributedString* attachment_string =
[NSAttributedString attributedStringWithAttachment:attachment];
[text appendAttributedString:attachment_string];
}
// Appends a carat string and some spacing to |text|.
void AppendCarat(NSMutableAttributedString* text, NSDictionary* attributes) {
// Use a carat facing the appropriate direction for the language.
NSString* carat = [NSString
stringWithFormat:@" %@ ", UseRTLLayout() ? @"\u25C2" : @"\u25B8"];
[text appendAttributedString:[[NSAttributedString alloc]
initWithString:carat
attributes:attributes]];
}
// Returns the string to use to describe the buttons needed to access the "Read
// Later" option.
NSAttributedString* GetInstructionIconString() {
NSDictionary* attributes = GetInstructionAttributes();
NSMutableAttributedString* icon_string =
[[NSMutableAttributedString alloc] init];
if (experimental_flags::IsReadingListUIRebootEnabled()) {
// In the UI reboot, only the single tools icon is used.
AppendIcon(IconType::TOOLS, icon_string, attributes);
} else {
if (IsCompactWidth() || !IsIPadIdiom()) {
// TODO(crbug.com/698726): When the share icon is displayed in the toolbar
// for landscape iPhone 6+, remove !IsIPadIdiom().
// If the device has a compact display the share menu is accessed from the
// toolbar menu. If it is expanded, the share menu is directly accessible.
AppendIcon(IconType::TOOLS, icon_string, attributes);
AppendCarat(icon_string, attributes);
}
AppendIcon(IconType::SHARE, icon_string, attributes);
AppendCarat(icon_string, attributes);
// Append an additional space at the end of the legacy icon string to
// improve the kerning between the carat and the "Read Later" text.
[icon_string appendAttributedString:[[NSAttributedString alloc]
initWithString:@" "
attributes:attributes]];
}
return icon_string;
}
// Returns the icon string in an accessible format.
NSAttributedString* GetAccessibleInstructionIconString() {
NSDictionary* attributes = GetInstructionAttributes();
NSMutableAttributedString* icon_string =
[[NSMutableAttributedString alloc] initWithString:@":"
attributes:attributes];
if (experimental_flags::IsReadingListUIRebootEnabled()) {
NSString* tools_text = [NSString
stringWithFormat:@"%@, ",
l10n_util::GetNSString(IDS_IOS_TOOLBAR_SETTINGS)];
[icon_string appendAttributedString:[[NSAttributedString alloc]
initWithString:tools_text
attributes:attributes]];
} else {
if ((IsCompactWidth() || !IsIPadIdiom())) {
NSString* tools_text = [NSString
stringWithFormat:@"%@, ",
l10n_util::GetNSString(IDS_IOS_TOOLBAR_SETTINGS)];
[icon_string appendAttributedString:[[NSAttributedString alloc]
initWithString:tools_text
attributes:attributes]];
}
NSString* share_text = [NSString
stringWithFormat:@"%@, ",
l10n_util::GetNSString(IDS_IOS_TOOLS_MENU_SHARE)];
[icon_string appendAttributedString:[[NSAttributedString alloc]
initWithString:share_text
attributes:attributes]];
}
return icon_string;
}
// Returns the attributed text to use for the message. If |use_icons| is true,
// icon images are added to the text; otherwise accessible text versions of the
// instructions are used.
NSAttributedString* GetReadingListEmptyMessage(bool use_icons) {
bool reboot_enabled = experimental_flags::IsReadingListUIRebootEnabled();
NSString* raw_text = l10n_util::GetNSString(
reboot_enabled ? IDS_IOS_READING_LIST_EMPTY_MESSAGE
: IDS_IOS_READING_LIST_EMPTY_MESSAGE_LEGACY);
NSMutableAttributedString* message =
[[NSMutableAttributedString alloc] initWithString:raw_text
attributes:GetMessageAttributes()];
NSAttributedString* instruction_icon_string =
use_icons ? GetInstructionIconString()
: GetAccessibleInstructionIconString();
NSAttributedString* read_later_string = GetReadLaterString();
if (reboot_enabled) {
// When the reboot is enabled, two replacements must be made in the text:
// - kOpenShareMarker should be replaced with |instruction_icon_string|
// - kReadLaterTextMarker should be replaced with |read_later_text|
NSRange icon_range = [message.string rangeOfString:kOpenShareMarker];
DCHECK(icon_range.location != NSNotFound);
[message replaceCharactersInRange:icon_range
withAttributedString:instruction_icon_string];
NSRange read_later_range =
[message.string rangeOfString:kReadLaterTextMarker];
DCHECK(read_later_range.location != NSNotFound);
[message replaceCharactersInRange:read_later_range
withAttributedString:read_later_string];
} else {
// In the legacy implementation, kOpenShareMarker is replaced with the
// entire instruction string (i.e. "(tools icon) > (share icon) > Read
// Later".
NSMutableAttributedString* instruction_string =
[[NSMutableAttributedString alloc] init];
[instruction_string appendAttributedString:instruction_icon_string];
[instruction_string appendAttributedString:read_later_string];
NSRange replacement_range = [message.string rangeOfString:kOpenShareMarker];
DCHECK(replacement_range.location != NSNotFound);
[message replaceCharactersInRange:replacement_range
withAttributedString:instruction_string];
}
return message;
}
} // namespace
NSAttributedString* GetReadingListEmptyMessage() {
return GetReadingListEmptyMessage(true);
}
NSString* GetReadingListEmptyMessageA11yLabel() {
return GetReadingListEmptyMessage(false).string;
}
...@@ -4,24 +4,6 @@ ...@@ -4,24 +4,6 @@
import("//build/config/ios/asset_catalog.gni") import("//build/config/ios/asset_catalog.gni")
imageset("reading_list_share_icon") {
sources = [
"reading_list_share_icon.imageset/Contents.json",
"reading_list_share_icon.imageset/reading_list_share_icon.png",
"reading_list_share_icon.imageset/reading_list_share_icon@2x.png",
"reading_list_share_icon.imageset/reading_list_share_icon@3x.png",
]
}
imageset("reading_list_toolbar_icon") {
sources = [
"reading_list_toolbar_icon.imageset/Contents.json",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon.png",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon@2x.png",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon@3x.png",
]
}
imageset("distillation_fail") { imageset("distillation_fail") {
sources = [ sources = [
"distillation_fail.imageset/Contents.json", "distillation_fail.imageset/Contents.json",
...@@ -40,12 +22,12 @@ imageset("distillation_fail_new") { ...@@ -40,12 +22,12 @@ imageset("distillation_fail_new") {
] ]
} }
imageset("reading_list_side_swipe") { imageset("distillation_success") {
sources = [ sources = [
"reading_list_side_swipe.imageset/Contents.json", "distillation_success.imageset/Contents.json",
"reading_list_side_swipe.imageset/reading_list_side_swipe.png", "distillation_success.imageset/distillation_success.png",
"reading_list_side_swipe.imageset/reading_list_side_swipe@2x.png", "distillation_success.imageset/distillation_success@2x.png",
"reading_list_side_swipe.imageset/reading_list_side_swipe@3x.png", "distillation_success.imageset/distillation_success@3x.png",
] ]
} }
...@@ -58,11 +40,47 @@ imageset("reading_list_empty_state") { ...@@ -58,11 +40,47 @@ imageset("reading_list_empty_state") {
] ]
} }
imageset("distillation_success") { imageset("reading_list_empty_state_new") {
sources = [ sources = [
"distillation_success.imageset/Contents.json", "reading_list_empty_state_new.imageset/Contents.json",
"distillation_success.imageset/distillation_success.png", "reading_list_empty_state_new.imageset/reading_list_empty_state_new.png",
"distillation_success.imageset/distillation_success@2x.png", "reading_list_empty_state_new.imageset/reading_list_empty_state_new@2x.png",
"distillation_success.imageset/distillation_success@3x.png", "reading_list_empty_state_new.imageset/reading_list_empty_state_new@3x.png",
]
}
imageset("reading_list_share_icon") {
sources = [
"reading_list_share_icon.imageset/Contents.json",
"reading_list_share_icon.imageset/reading_list_share_icon.png",
"reading_list_share_icon.imageset/reading_list_share_icon@2x.png",
"reading_list_share_icon.imageset/reading_list_share_icon@3x.png",
]
}
imageset("reading_list_side_swipe") {
sources = [
"reading_list_side_swipe.imageset/Contents.json",
"reading_list_side_swipe.imageset/reading_list_side_swipe.png",
"reading_list_side_swipe.imageset/reading_list_side_swipe@2x.png",
"reading_list_side_swipe.imageset/reading_list_side_swipe@3x.png",
]
}
imageset("reading_list_toolbar_icon") {
sources = [
"reading_list_toolbar_icon.imageset/Contents.json",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon.png",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon@2x.png",
"reading_list_toolbar_icon.imageset/reading_list_toolbar_icon@3x.png",
]
}
imageset("reading_list_tools_icon") {
sources = [
"reading_list_tools_icon.imageset/Contents.json",
"reading_list_tools_icon.imageset/reading_list_tools_icon.png",
"reading_list_tools_icon.imageset/reading_list_tools_icon@2x.png",
"reading_list_tools_icon.imageset/reading_list_tools_icon@3x.png",
] ]
} }
{
"images": [
{
"idiom": "universal",
"scale": "1x",
"filename": "reading_list_empty_state_new.png"
},
{
"idiom": "universal",
"scale": "2x",
"filename": "reading_list_empty_state_new@2x.png"
},
{
"idiom": "universal",
"scale": "3x",
"filename": "reading_list_empty_state_new@3x.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "universal",
"scale": "1x",
"filename": "reading_list_tools_icon.png"
},
{
"idiom": "universal",
"scale": "2x",
"filename": "reading_list_tools_icon@2x.png"
},
{
"idiom": "universal",
"scale": "3x",
"filename": "reading_list_tools_icon@3x.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
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