Skip to content

Commit

Permalink
Implement height-based animation for Toast on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Dec 2, 2024
1 parent c7ecffe commit aec3d26
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
#include "brave/grit/brave_generated_resources.h"
#include "build/build_config.h"
#include "chrome/browser/infobars/confirm_infobar_creator.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
Expand All @@ -24,8 +25,6 @@ namespace brave_ads {

namespace {

constexpr int kIconSize = 20;

constexpr char kLearnMoreUrl[] =
"https://search.brave.com/help/conversion-reporting";

Expand All @@ -48,9 +47,8 @@ void CreativeSearchResultAdClickedInfoBarDelegate::Create(
if (!infobar_manager) {
return;
}
infobar_manager->AddInfoBar(
CreateConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate>(
new CreativeSearchResultAdClickedInfoBarDelegate())));
infobar_manager->AddInfoBar(CreateConfirmInfoBar(
std::make_unique<CreativeSearchResultAdClickedInfoBarDelegate>()));
}

CreativeSearchResultAdClickedInfoBarDelegate::
Expand All @@ -65,8 +63,12 @@ CreativeSearchResultAdClickedInfoBarDelegate::GetIdentifier() const {
}

ui::ImageModel CreativeSearchResultAdClickedInfoBarDelegate::GetIcon() const {
#if BUILDFLAG(IS_ANDROID)
return ui::ImageModel();
#else
return ui::ImageModel::FromVectorIcon(vector_icons::kProductIcon,
ui::kColorIcon, kIconSize);
ui::kColorIcon, /*icon_size=*/20);
#endif // BUILDFLAG(IS_ANDROID)
}

std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetMessageText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ButtonToast: Toast {

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

self.snp.makeConstraints { make in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DownloadToast: Toast {

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

self.snp.makeConstraints { make in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PlaylistToast: Toast {

toastView.snp.makeConstraints {
$0.leading.trailing.height.equalTo(self)
self.animationConstraint = $0.top.equalTo(self).offset(ButtonToastUX.toastHeight).constraint
self.animationConstraint = $0.top.equalTo(self.snp.bottom).constraint
}

self.snp.makeConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SwiftUI
import UIKit

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.preferredFont(forTextStyle: .subheadline)
Expand Down Expand Up @@ -45,7 +44,7 @@ class SearchResultAdClickedInfoBar: Toast, UITextViewDelegate {
addSubview(toastView)
toastView.snp.makeConstraints { make in
make.left.right.height.equalTo(self)
self.animationConstraint = make.top.equalTo(self).offset(SimpleToastUX.toastHeight).constraint
self.animationConstraint = make.top.equalTo(self.snp.bottom).constraint
}
}

Expand Down
4 changes: 2 additions & 2 deletions ios/brave-ios/Sources/Brave/Frontend/Browser/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Toast: UIView {
UIView.animate(
withDuration: SimpleToastUX.toastAnimationDuration,
animations: {
self.animationConstraint?.update(offset: 0)
self.animationConstraint?.update(offset: -self.bounds.height)
self.layoutIfNeeded()
},
completion: { finished in
Expand Down Expand Up @@ -83,7 +83,7 @@ class Toast: UIView {
UIView.animate(
withDuration: duration,
animations: {
self.animationConstraint?.update(offset: SimpleToastUX.toastHeight)
self.animationConstraint?.update(offset: 0)
self.layoutIfNeeded()
},
completion: { finished in
Expand Down

0 comments on commit aec3d26

Please sign in to comment.