From 0e78b3953ba5bb17c6cffac58c07e4c23228c092 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 1 Dec 2022 16:52:03 +1100 Subject: [PATCH] refactor info banner --- Session/Conversations/ConversationVC.swift | 8 +++- .../Views & Modals/InfoBanner.swift | 45 +++++++++++++++---- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 2d52bcc68..d126be3f5 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -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) diff --git a/Session/Conversations/Views & Modals/InfoBanner.swift b/Session/Conversations/Views & Modals/InfoBanner.swift index 97893a3cc..454e8f69a 100644 --- a/Session/Conversations/Views & Modals/InfoBanner.swift +++ b/Session/Conversations/Views & Modals/InfoBanner.swift @@ -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) } }