Skip to content

Commit

Permalink
[ads] Update search ad clicked infobar text and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Sep 12, 2024
1 parent 75ba9d6 commit b4fe7f6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 78 deletions.
5 changes: 4 additions & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
You don't need to click to earn, but do click if you're interested!
</message>
<message name="IDS_BRAVE_ADS_SEARCH_RESULT_AD_CLICKED_INFOBAR_MESSAGE" desc="The text label of creative search result ad infobar message">
You’ve just clicked on a Brave Search ad. Unlike Big Tech, we measure ad performance anonymously and preserve your privacy.
Thank you for supporting Brave Search by clicking on a private ad! Unlike Big Tech, we measure ad performance anonymously and preserve your privacy.
</message>
<message name="IDS_BRAVE_ADS_SEARCH_RESULT_AD_LEARN_MORE_OPT_OUT_CHOICES_LABEL" desc="The text label of creative search result ad learn more / opt out choices link">
Learn more / opt out choices
</message>

<!-- Brave Search -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <memory>

#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
#include "brave/components/vector_icons/vector_icons.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/infobars/confirm_infobar_creator.h"
#include "components/infobars/content/content_infobar_manager.h"
Expand All @@ -18,12 +17,15 @@
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "url/gurl.h"

namespace brave_ads {

namespace {

constexpr int kIconSize = 20;

constexpr char kLearnMoreUrl[] =
"https://support.brave.com/hc/en-us/articles/360026361072-Brave-Ads-FAQ";

Expand Down Expand Up @@ -62,9 +64,9 @@ CreativeSearchResultAdClickedInfoBarDelegate::GetIdentifier() const {
return SEARCH_RESULT_AD_CLICKED_INFOBAR_DELEGATE;
}

const gfx::VectorIcon&
CreativeSearchResultAdClickedInfoBarDelegate::GetVectorIcon() const {
return kLeoBraveIconReleaseColorIcon;
ui::ImageModel CreativeSearchResultAdClickedInfoBarDelegate::GetIcon() const {
return ui::ImageModel::FromVectorIcon(vector_icons::kProductIcon,
ui::kColorIcon, kIconSize);
}

std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetMessageText()
Expand All @@ -79,7 +81,8 @@ int CreativeSearchResultAdClickedInfoBarDelegate::GetButtons() const {

std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetLinkText()
const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
return l10n_util::GetStringUTF16(
IDS_BRAVE_ADS_SEARCH_RESULT_AD_LEARN_MORE_OPT_OUT_CHOICES_LABEL);
}

GURL CreativeSearchResultAdClickedInfoBarDelegate::GetLinkURL() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CreativeSearchResultAdClickedInfoBarDelegate
private:
// ConfirmInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
const gfx::VectorIcon& GetVectorIcon() const override;
ui::ImageModel GetIcon() const override;
std::u16string GetMessageText() const override;
int GetButtons() const override;
std::u16string GetLinkText() const override;
Expand Down
1 change: 0 additions & 1 deletion components/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ aggregate_vector_icons("brave_components_vector_icons") {
"leo_arrow_right.icon",
"leo_arrow_small_right.icon",
"leo_brave_icon_monochrome.icon",
"leo_brave_icon_release_color.icon",
"leo_browser_add.icon",
"leo_browser_bookmark_add.icon",
"leo_browser_bookmark_plural.icon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SnapKit
import SwiftUI
import UIKit

struct SearchResultAdClickedInfoBarUX {
private struct SearchResultAdClickedInfoBarUX {
static let toastHeight: CGFloat = 100.0
static let toastPadding: CGFloat = 10.0
static let toastCloseButtonWidth: CGFloat = 20.0
static let toastLabelFont = UIFont.systemFont(ofSize: 15, weight: .semibold)
static let toastLabelFont = UIFont.preferredFont(forTextStyle: .subheadline)
static let toastBackgroundColor = UIColor(braveSystemName: .schemesOnPrimaryFixed)
static let learnMoreUrl = "https://support.brave.com/hc/en-us/articles/360026361072-Brave-Ads-FAQ"
}
Expand All @@ -29,30 +29,31 @@ class SearchResultAdClickedInfoBar: Toast, UITextViewDelegate {
self.tapDismissalMode = .outsideTap

self.clipsToBounds = true
self.addSubview(
createView(
Strings.searchResultAdsClickedInfoBarTitle + " "
)
)

self.toastView.backgroundColor = SearchResultAdClickedInfoBarUX.toastBackgroundColor
toastView.backgroundColor = SearchResultAdClickedInfoBarUX.toastBackgroundColor

self.toastView.snp.makeConstraints { make in
make.left.right.height.equalTo(self)
self.animationConstraint =
make.top.equalTo(self).offset(SearchResultAdClickedInfoBarUX.toastHeight).constraint
let toastContent = createToastContent(
Strings.searchResultAdClickedInfoBarTitle + " "
)
toastView.addSubview(toastContent)
toastContent.snp.makeConstraints { make in
make.centerX.equalTo(toastView)
make.centerY.equalTo(toastView)
make.edges.equalTo(toastView).inset(SearchResultAdClickedInfoBarUX.toastPadding)
}

self.snp.makeConstraints { make in
make.height.equalTo(SearchResultAdClickedInfoBarUX.toastHeight)
addSubview(toastView)
toastView.snp.makeConstraints { make in
make.left.right.height.equalTo(self)
self.animationConstraint = make.top.equalTo(self).offset(SimpleToastUX.toastHeight).constraint
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

fileprivate func createView(
fileprivate func createToastContent(
_ labelText: String
) -> UIView {
let horizontalStackView = UIStackView()
Expand All @@ -70,7 +71,7 @@ class SearchResultAdClickedInfoBar: Toast, UITextViewDelegate {
label.isSelectable = true
label.delegate = self

let learnMoreText = Strings.learnMore.withNonBreakingSpace
let learnMoreOptOutChoicesText = Strings.searchResultAdClickedLearnMoreOptOutChoicesLabel
let attributes: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.white,
.font: SearchResultAdClickedInfoBarUX.toastLabelFont,
Expand All @@ -88,52 +89,34 @@ class SearchResultAdClickedInfoBar: Toast, UITextViewDelegate {
attributes: attributes
)
let nsLinkAttributedString = NSMutableAttributedString(
string: learnMoreText,
string: learnMoreOptOutChoicesText,
attributes: linkAttributes
)

if let url = URL(string: SearchResultAdClickedInfoBarUX.learnMoreUrl) {
let learnMoreRange = NSRange(location: 0, length: learnMoreText.count)
nsLinkAttributedString.addAttribute(.link, value: url, range: learnMoreRange)
let linkTextRange = NSRange(location: 0, length: learnMoreOptOutChoicesText.count)
nsLinkAttributedString.addAttribute(.link, value: url, range: linkTextRange)
nsLabelAttributedString.append(nsLinkAttributedString)
label.isUserInteractionEnabled = true
}
label.attributedText = nsLabelAttributedString

horizontalStackView.addArrangedSubview(label)

if let buttonImage = UIImage(braveSystemNamed: "leo.close") {
let button = UIButton()
button.setImage(buttonImage, for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.imageView?.tintColor = .white
button.imageView?.preferredSymbolConfiguration = .init(
font: .preferredFont(for: .title3, weight: .regular),
scale: .small
)

button.imageView?.snp.makeConstraints {
$0.width.equalTo(SearchResultAdClickedInfoBarUX.toastCloseButtonWidth)
}

button.addGestureRecognizer(
UITapGestureRecognizer(target: self, action: #selector(buttonPressed))
)

horizontalStackView.addArrangedSubview(button)
}

toastView.addSubview(horizontalStackView)

horizontalStackView.snp.makeConstraints { make in
make.centerX.equalTo(toastView)
make.centerY.equalTo(toastView)
make.width.equalTo(toastView.snp.width).offset(
-2 * SearchResultAdClickedInfoBarUX.toastPadding
)
let button = UIButton()
button.setImage(UIImage(braveSystemNamed: "leo.close")!, for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.imageView?.tintColor = .white
button.imageView?.preferredSymbolConfiguration = .init(
font: .preferredFont(for: .title3, weight: .regular),
scale: .small
)
button.snp.makeConstraints {
$0.width.equalTo(SearchResultAdClickedInfoBarUX.toastCloseButtonWidth)
}
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
horizontalStackView.addArrangedSubview(button)

return toastView
return horizontalStackView
}

func textView(
Expand All @@ -153,19 +136,4 @@ class SearchResultAdClickedInfoBar: Toast, UITextViewDelegate {
@objc func buttonPressed(_ gestureRecognizer: UIGestureRecognizer) {
dismiss(true)
}

override func showToast(
viewController: UIViewController? = nil,
delay: DispatchTimeInterval = SimpleToastUX.toastDelayBefore,
duration: DispatchTimeInterval?,
makeConstraints: @escaping (ConstraintMaker) -> Void,
completion: (() -> Void)? = nil
) {
super.showToast(
viewController: viewController,
delay: delay,
duration: duration,
makeConstraints: makeConstraints
)
}
}
17 changes: 12 additions & 5 deletions ios/brave-ios/Sources/Shared/SharedStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,19 @@ extension Strings {
)
}

// Search result ad clicked InfoBar title
// Search result ad clicked InfoBar title and learn more / opt out choices link.
extension Strings {
public static let searchResultAdsClickedInfoBarTitle = NSLocalizedString(
"SearchResultAdsClickedInfoBarTitle",
public static let searchResultAdClickedInfoBarTitle = NSLocalizedString(
"SearchResultAdClickedInfoBarTitle",
bundle: .module,
value: "You’ve just clicked on a Brave Search ad. Unlike Big Tech, we measure ad performance anonymously and preserve your privacy.",
comment: "InfoBar displayed after a user clicked a search result ad for the first time."
value: "Thank you for supporting Brave Search by clicking on a private ad! Unlike Big Tech, we measure ad performance anonymously and preserve your privacy.",
comment: "The text label of creative search result ad infobar message."
)

public static let searchResultAdClickedLearnMoreOptOutChoicesLabel = NSLocalizedString(
"SearchResultAdClickedLearnMoreOptOutChoicesLabel",
bundle: .module,
value: "Learn more / opt out choices",
comment: "The text label of creative search result ad learn more / opt out choices link."
)
}

0 comments on commit b4fe7f6

Please sign in to comment.