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 Nov 20, 2024
1 parent 936b7e4 commit a722194
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
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).offset(0).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).offset(0).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).offset(0).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).offset(0).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 a722194

Please sign in to comment.