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 10, 2024
1 parent dca4cf9 commit c3fdf69
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 73 deletions.
5 changes: 4 additions & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,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 @@ -64,7 +64,7 @@ CreativeSearchResultAdClickedInfoBarDelegate::GetIdentifier() const {

const gfx::VectorIcon&
CreativeSearchResultAdClickedInfoBarDelegate::GetVectorIcon() const {
return kLeoBraveIconReleaseColorIcon;
return vector_icons::kProductIcon;
}

std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetMessageText()
Expand All @@ -79,7 +79,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 @@ -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 c3fdf69

Please sign in to comment.