Merge pull request #585 from mpretty-cyro/feature/image-tinting-optimisations

Performance: Image tinting optimisations
This commit is contained in:
RyanZhao 2022-03-21 13:56:51 +11:00 committed by GitHub
commit 1b21951335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 27 deletions

View File

@ -254,8 +254,9 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
let authorLabelSize = authorLabel.sizeThatFits(authorLabelAvailableSpace)
authorLabelHeightConstraint.constant = (viewItem.senderName != nil) ? authorLabelSize.height : 0
// Message status image view
let (image, backgroundColor) = getMessageStatusImage(for: message)
let (image, tintColor, backgroundColor) = getMessageStatusImage(for: message)
messageStatusImageView.image = image
messageStatusImageView.tintColor = tintColor
messageStatusImageView.backgroundColor = backgroundColor
if let message = message as? TSOutgoingMessage {
messageStatusImageView.isHidden = (message.messageState == .sent && thread?.lastInteraction != message)
@ -612,20 +613,33 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
}
}
private func getMessageStatusImage(for message: TSMessage) -> (image: UIImage?, backgroundColor: UIColor?) {
guard let message = message as? TSOutgoingMessage else { return (nil, nil) }
private func getMessageStatusImage(for message: TSMessage) -> (image: UIImage?, tintColor: UIColor?, backgroundColor: UIColor?) {
guard let message = message as? TSOutgoingMessage else { return (nil, nil, nil) }
let image: UIImage
var tintColor: UIColor? = nil
var backgroundColor: UIColor? = nil
let status = MessageRecipientStatusUtils.recipientStatus(outgoingMessage: message)
switch status {
case .uploading, .sending: image = #imageLiteral(resourceName: "CircleDotDotDot").asTintedImage(color: Colors.text)!
case .sent, .skipped, .delivered: image = #imageLiteral(resourceName: "CircleCheck").asTintedImage(color: Colors.text)!
case .read:
backgroundColor = isLightMode ? .black : .white
image = isLightMode ? #imageLiteral(resourceName: "FilledCircleCheckLightMode") : #imageLiteral(resourceName: "FilledCircleCheckDarkMode")
case .failed: image = #imageLiteral(resourceName: "message_status_failed").asTintedImage(color: Colors.destructive)!
case .uploading, .sending:
image = #imageLiteral(resourceName: "CircleDotDotDot").withRenderingMode(.alwaysTemplate)
tintColor = Colors.text
case .sent, .skipped, .delivered:
image = #imageLiteral(resourceName: "CircleCheck").withRenderingMode(.alwaysTemplate)
tintColor = Colors.text
case .read:
image = isLightMode ? #imageLiteral(resourceName: "FilledCircleCheckLightMode") : #imageLiteral(resourceName: "FilledCircleCheckDarkMode")
backgroundColor = isLightMode ? .black : .white
case .failed:
image = #imageLiteral(resourceName: "message_status_failed").withRenderingMode(.alwaysTemplate)
tintColor = Colors.destructive
}
return (image, backgroundColor)
return (image, tintColor, backgroundColor)
}
private func getSize(for viewItem: ConversationViewItem) -> CGSize {

View File

@ -321,19 +321,30 @@ final class ConversationCell : UITableViewCell {
statusIndicatorView.backgroundColor = nil
let lastMessage = threadViewModel.lastMessageForInbox
if let lastMessage = lastMessage as? TSOutgoingMessage {
let image: UIImage
let status = MessageRecipientStatusUtils.recipientStatus(outgoingMessage: lastMessage)
switch status {
case .uploading, .sending: image = #imageLiteral(resourceName: "CircleDotDotDot").asTintedImage(color: Colors.text)!
case .sent, .skipped, .delivered: image = #imageLiteral(resourceName: "CircleCheck").asTintedImage(color: Colors.text)!
case .read:
statusIndicatorView.backgroundColor = isLightMode ? .black : .white
image = isLightMode ? #imageLiteral(resourceName: "FilledCircleCheckLightMode") : #imageLiteral(resourceName: "FilledCircleCheckDarkMode")
case .failed: image = #imageLiteral(resourceName: "message_status_failed").asTintedImage(color: Colors.text)!
case .uploading, .sending:
statusIndicatorView.image = #imageLiteral(resourceName: "CircleDotDotDot").withRenderingMode(.alwaysTemplate)
statusIndicatorView.tintColor = Colors.text
case .sent, .skipped, .delivered:
statusIndicatorView.image = #imageLiteral(resourceName: "CircleCheck").withRenderingMode(.alwaysTemplate)
statusIndicatorView.tintColor = Colors.text
case .read:
statusIndicatorView.image = isLightMode ? #imageLiteral(resourceName: "FilledCircleCheckLightMode") : #imageLiteral(resourceName: "FilledCircleCheckDarkMode")
statusIndicatorView.tintColor = nil
statusIndicatorView.backgroundColor = (isLightMode ? .black : .white)
case .failed:
statusIndicatorView.image = #imageLiteral(resourceName: "message_status_failed").withRenderingMode(.alwaysTemplate)
statusIndicatorView.tintColor = Colors.destructive
}
statusIndicatorView.image = image
statusIndicatorView.isHidden = false
} else {
}
else {
statusIndicatorView.isHidden = true
}
}

View File

@ -83,16 +83,22 @@ final class UserCell : UITableViewCell {
profilePictureView.publicKey = publicKey
profilePictureView.update()
displayNameLabel.text = Storage.shared.getContact(with: publicKey)?.displayName(for: .regular) ?? publicKey
switch accessory {
case .none: accessoryImageView.isHidden = true
case .lock:
accessoryImageView.isHidden = false
accessoryImageView.image = #imageLiteral(resourceName: "ic_lock_outline").asTintedImage(color: Colors.text.withAlphaComponent(Values.mediumOpacity))!
case .tick(let isSelected):
accessoryImageView.isHidden = false
let icon = isSelected ? #imageLiteral(resourceName: "CircleCheck") : #imageLiteral(resourceName: "Circle")
accessoryImageView.image = isDarkMode ? icon : icon.asTintedImage(color: Colors.text)!
case .none: accessoryImageView.isHidden = true
case .lock:
accessoryImageView.isHidden = false
accessoryImageView.image = #imageLiteral(resourceName: "ic_lock_outline").withRenderingMode(.alwaysTemplate)
accessoryImageView.tintColor = Colors.text.withAlphaComponent(Values.mediumOpacity)
case .tick(let isSelected):
let icon: UIImage = (isSelected ? #imageLiteral(resourceName: "CircleCheck") : #imageLiteral(resourceName: "Circle"))
accessoryImageView.isHidden = false
accessoryImageView.image = icon.withRenderingMode(.alwaysTemplate)
accessoryImageView.tintColor = Colors.text
}
let alpha: CGFloat = isZombie ? 0.5 : 1
[ profilePictureView, displayNameLabel, accessoryImageView ].forEach { $0.alpha = alpha }
}