refactor info banner

pull/941/head
Ryan Zhao 2 years ago
parent 70e4a51780
commit 0e78b3953b

@ -194,10 +194,14 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
}()
lazy var blockedBanner: InfoBanner = {
let result: InfoBanner = InfoBanner(
let info: InfoBanner.Info = InfoBanner.Info(
message: self.viewModel.blockedBannerMessage,
backgroundColor: .danger
backgroundColor: .danger,
messageFont: .boldSystemFont(ofSize: Values.smallFontSize),
messageTintColor: .textPrimary,
height: 54
)
let result: InfoBanner = InfoBanner(info: info)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(unblock))
result.addGestureRecognizer(tapGestureRecognizer)

@ -4,10 +4,38 @@ import UIKit
import SessionUIKit
final class InfoBanner: UIView {
init(message: String, backgroundColor: ThemeValue) {
public struct Info: Equatable, Hashable {
let message: String
let backgroundColor: ThemeValue
let messageFont: UIFont
let messageTintColor: ThemeValue
let height: CGFloat
// MARK: - Confirmance
public static func == (lhs: InfoBanner.Info, rhs: InfoBanner.Info) -> Bool {
return (
lhs.message == rhs.message &&
lhs.backgroundColor == rhs.backgroundColor &&
lhs.messageFont == rhs.messageFont &&
lhs.messageTintColor == rhs.messageTintColor &&
lhs.height == rhs.height
)
}
public func hash(into hasher: inout Hasher) {
message.hash(into: &hasher)
backgroundColor.hash(into: &hasher)
messageFont.hash(into: &hasher)
messageTintColor.hash(into: &hasher)
height.hash(into: &hasher)
}
}
init(info: Info) {
super.init(frame: CGRect.zero)
setUpViewHierarchy(message: message, backgroundColor: backgroundColor)
setUpViewHierarchy(info)
}
override init(frame: CGRect) {
@ -18,18 +46,19 @@ final class InfoBanner: UIView {
preconditionFailure("Use init(coder:) instead.")
}
private func setUpViewHierarchy(message: String, backgroundColor: ThemeValue) {
themeBackgroundColor = backgroundColor
private func setUpViewHierarchy(_ info: InfoBanner.Info) {
themeBackgroundColor = info.backgroundColor
let label: UILabel = UILabel()
label.font = .boldSystemFont(ofSize: Values.smallFontSize)
label.text = message
label.themeTextColor = .textPrimary
label.font = info.messageFont
label.text = info.message
label.themeTextColor = info.messageTintColor
label.textAlignment = .center
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
addSubview(label)
label.pin(to: self, withInset: Values.mediumSpacing)
label.center(in: self)
self.set(.height, to: info.height)
}
}

Loading…
Cancel
Save