fix outdated client banner in conversation screen

pull/731/head
Ryan ZHAO 7 months ago
parent 21c4a17a85
commit 666061fec9

@ -207,12 +207,12 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
let info: InfoBanner.Info = InfoBanner.Info(
message: String(format: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(), self.viewModel.threadData.displayName),
backgroundColor: .primary,
messageFont: .systemFont(ofSize: Values.miniFontSize),
messageFont: .systemFont(ofSize: Values.verySmallFontSize),
messageTintColor: .messageBubble_outgoingText,
messageLabelAccessibilityLabel: "Outdated client banner text",
height: 40
)
let result: InfoBanner = InfoBanner(info: info)
let result: InfoBanner = InfoBanner(info: info, dismiss: self.removeOutdatedClientBanner)
result.accessibilityLabel = "Outdated client banner"
result.isAccessibilityElement = true
@ -806,7 +806,13 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
.defaulting(to: NSRange(location: 0, length: 0))
)
outdatedClientBanner.update(message: String(format: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(), updatedThreadData.displayName))
outdatedClientBanner.update(
message: String(
format: "DISAPPEARING_MESSAGES_OUTDATED_CLIENT_BANNER".localized(),
updatedThreadData.displayName
),
dismiss: self.removeOutdatedClientBanner
)
}
if
@ -872,9 +878,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
}
}
if initialLoad || viewModel.threadData.contactLastKnownClientVersion != updatedThreadData.contactLastKnownClientVersion {
addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: updatedThreadData.contactLastKnownClientVersion == .legacyDisappearingMessages)
}
addOrRemoveOutdatedClientBanner(contactIsUsingOutdatedClient: updatedThreadData.contactLastKnownClientVersion == .legacyDisappearingMessages)
if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked {
addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true))
@ -1510,23 +1514,27 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
}
guard contactIsUsingOutdatedClient else {
UIView.animate(
withDuration: 0.25,
animations: { [weak self] in
self?.outdatedClientBanner.alpha = 0
},
completion: { [weak self] _ in
self?.outdatedClientBanner.isHidden = true
self?.outdatedClientBanner.alpha = 1
self?.emptyStateLabelTopConstraint?.constant = Values.largeSpacing
}
)
removeOutdatedClientBanner()
return
}
self.outdatedClientBanner.isHidden = false
self.emptyStateLabelTopConstraint?.constant = 0
}
private func removeOutdatedClientBanner() {
UIView.animate(
withDuration: 0.25,
animations: { [weak self] in
self?.outdatedClientBanner.alpha = 0
},
completion: { [weak self] _ in
self?.outdatedClientBanner.isHidden = true
self?.outdatedClientBanner.alpha = 1
self?.emptyStateLabelTopConstraint?.constant = Values.largeSpacing
}
)
}
func addOrRemoveBlockedBanner(threadIsBlocked: Bool) {
guard threadIsBlocked else {

@ -41,22 +41,45 @@ final class InfoBanner: UIView {
return result
}()
private lazy var closeButton: UIButton = {
let result: UIButton = UIButton()
result.translatesAutoresizingMaskIntoConstraints = false
result.setImage(
UIImage(systemName: "xmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 12, weight: .bold))?
.withRenderingMode(.alwaysTemplate),
for: .normal
)
result.contentMode = .center
result.addTarget(self, action: #selector(dismissBanner), for: .touchUpInside)
return result
}()
public var info: Info?
public var dismiss: (() -> Void)?
// MARK: - Initialization
init(info: Info) {
init(info: Info, dismiss: (() -> Void)? = nil) {
super.init(frame: CGRect.zero)
addSubview(label)
label.pin(.top, to: .top, of: self)
label.pin(.bottom, to: .bottom, of: self)
label.pin(.leading, to: .leading, of: self, withInset: Values.mediumSpacing)
label.pin(.trailing, to: .trailing, of: self, withInset: -Values.mediumSpacing)
label.pin(.leading, to: .leading, of: self, withInset: Values.veryLargeSpacing)
label.pin(.trailing, to: .trailing, of: self, withInset: -Values.veryLargeSpacing)
addSubview(closeButton)
let buttonSize: CGFloat = (12 + (Values.smallSpacing * 2))
closeButton.center(.vertical, in: self)
closeButton.pin(.trailing, to: .trailing, of: self, withInset: -Values.smallSpacing)
closeButton.set(.width, to: buttonSize)
closeButton.set(.height, to: buttonSize)
self.set(.height, to: info.height)
self.update(info)
self.update(info, dismiss: dismiss)
}
override init(frame: CGRect) {
@ -69,8 +92,9 @@ final class InfoBanner: UIView {
// MARK: Update
private func update(_ info: InfoBanner.Info) {
private func update(_ info: InfoBanner.Info, dismiss: (() -> Void)?) {
self.info = info
self.dismiss = dismiss
themeBackgroundColor = info.backgroundColor
@ -78,6 +102,9 @@ final class InfoBanner: UIView {
label.text = info.message
label.themeTextColor = info.messageTintColor
label.accessibilityLabel = info.messageLabelAccessibilityLabel
closeButton.themeTintColor = info.messageTintColor
closeButton.isHidden = (dismiss == nil)
}
public func update(
@ -86,7 +113,8 @@ final class InfoBanner: UIView {
messageFont: UIFont? = nil,
messageTintColor: ThemeValue? = nil,
messageLabelAccessibilityLabel: String? = nil,
height: CGFloat? = nil
height: CGFloat? = nil,
dismiss: (() -> Void)? = nil
) {
if let updatedInfo = self.info?.with(
message: message,
@ -96,7 +124,13 @@ final class InfoBanner: UIView {
messageLabelAccessibilityLabel: messageLabelAccessibilityLabel,
height: height
) {
self.update(updatedInfo)
self.update(updatedInfo, dismiss: dismiss)
}
}
// MARK: - Actions
@objc private func dismissBanner() {
self.dismiss?()
}
}

Loading…
Cancel
Save