diff --git a/Riot/Assets/Images.xcassets/Room/Pill/Contents.json b/Riot/Assets/Images.xcassets/Room/Pill/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Riot/Assets/Images.xcassets/Room/Pill/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/Contents.json b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/Contents.json new file mode 100644 index 000000000..3a4181e5d --- /dev/null +++ b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "pill_user.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "pill_user@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "pill_user@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user.png b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user.png new file mode 100644 index 000000000..abe8be288 Binary files /dev/null and b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user.png differ diff --git a/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@2x.png b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@2x.png new file mode 100644 index 000000000..b047760db Binary files /dev/null and b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@2x.png differ diff --git a/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@3x.png b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@3x.png new file mode 100644 index 000000000..62a8fcfe1 Binary files /dev/null and b/Riot/Assets/Images.xcassets/Room/Pill/pill_user.imageset/pill_user@3x.png differ diff --git a/Riot/Generated/Images.swift b/Riot/Generated/Images.swift index ccad26c35..ce4974083 100644 --- a/Riot/Generated/Images.swift +++ b/Riot/Generated/Images.swift @@ -244,6 +244,7 @@ internal class Asset: NSObject { internal static let locationPinIcon = ImageAsset(name: "location_pin_icon") internal static let locationShareIcon = ImageAsset(name: "location_share_icon") internal static let locationUserMarker = ImageAsset(name: "location_user_marker") + internal static let pillUser = ImageAsset(name: "pill_user") internal static let pollCheckboxDefault = ImageAsset(name: "poll_checkbox_default") internal static let pollCheckboxSelected = ImageAsset(name: "poll_checkbox_selected") internal static let pollDeleteIcon = ImageAsset(name: "poll_delete_icon") diff --git a/Riot/Modules/Pills/PillAttachmentView.swift b/Riot/Modules/Pills/PillAttachmentView.swift index 1c296b32f..e35e7eaad 100644 --- a/Riot/Modules/Pills/PillAttachmentView.swift +++ b/Riot/Modules/Pills/PillAttachmentView.swift @@ -112,25 +112,25 @@ class PillAttachmentView: UIView { computedWidth += sizes.avatarSideLength - case .asset(let name): + case .asset(let name, let parameters): let assetView = UIView(frame: CGRect(x: 0, y: 0, width: sizes.avatarSideLength, height: sizes.avatarSideLength)) - assetView.backgroundColor = theme.colors.links + assetView.backgroundColor = parameters.backgroundColor?.uiColor assetView.layer.cornerRadius = sizes.avatarSideLength / 2 assetView.isUserInteractionEnabled = false assetView.translatesAutoresizingMaskIntoConstraints = false let imageView = UIImageView(frame: .zero) - imageView.image = ImageAsset(name: name).image.withRenderingMode(.alwaysTemplate) - imageView.tintColor = theme.baseIconPrimaryColor + imageView.image = ImageAsset(name: name).image.withRenderingMode(UIImage.RenderingMode(rawValue: parameters.rawRenderingMode) ?? .automatic) + imageView.tintColor = parameters.tintColor?.uiColor ?? theme.baseIconPrimaryColor imageView.contentMode = .scaleAspectFit imageView.translatesAutoresizingMaskIntoConstraints = false assetView.addSubview(imageView) NSLayoutConstraint.activate([ - imageView.leadingAnchor.constraint(equalTo: assetView.leadingAnchor, constant: 2), - imageView.trailingAnchor.constraint(equalTo: assetView.trailingAnchor, constant: -2), - imageView.topAnchor.constraint(equalTo: assetView.topAnchor, constant: 2), - imageView.bottomAnchor.constraint(equalTo: assetView.bottomAnchor, constant: -2) + imageView.leadingAnchor.constraint(equalTo: assetView.leadingAnchor, constant: parameters.padding), + imageView.trailingAnchor.constraint(equalTo: assetView.trailingAnchor, constant: -parameters.padding), + imageView.topAnchor.constraint(equalTo: assetView.topAnchor, constant: parameters.padding), + imageView.bottomAnchor.constraint(equalTo: assetView.bottomAnchor, constant: -parameters.padding) ]) stack.addArrangedSubview(assetView) diff --git a/Riot/Modules/Pills/PillProvider.swift b/Riot/Modules/Pills/PillProvider.swift index 40a990389..61978e269 100644 --- a/Riot/Modules/Pills/PillProvider.swift +++ b/Riot/Modules/Pills/PillProvider.swift @@ -119,16 +119,27 @@ struct PillProvider { // fallback on getting the user from the session's store user = session.user(withUserId: userId) } + let avatarUrl = roomMember?.avatarUrl ?? user?.avatarUrl let displayName = roomMember?.displayname ?? user?.displayName ?? userId let isHighlighted = userId == session.myUserId + let avatar: PillTextAttachmentItem + if avatarUrl == nil { + avatar = .asset(named: "pill_user", + parameters: .init(tintColor: PillAssetColor(uiColor: ThemeService.shared().theme.colors.secondaryContent), + rawRenderingMode: UIImage.RenderingMode.alwaysOriginal.rawValue, + padding: 0.0)) + } else { + avatar = .avatar(url: avatarUrl, + string: displayName, + matrixId: userId) + } + let data = PillTextAttachmentData(pillType: .user(userId: userId), items: [ - .avatar(url: avatarUrl, - string: displayName, - matrixId: userId), + avatar, .text(displayName) ], isHighlighted: isHighlighted, @@ -156,7 +167,7 @@ struct PillProvider { let avatar: PillTextAttachmentItem if let room { - if let _ = session.spaceService.getSpace(withId: roomId) { + if session.spaceService.getSpace(withId: roomId) != nil { avatar = .spaceAvatar(url: room.avatarData.mxContentUri, string: displayName, matrixId: roomId) @@ -166,7 +177,9 @@ struct PillProvider { matrixId: roomId) } } else { - avatar = .asset(named: "link_icon") + avatar = .asset(named: "link_icon", + parameters: .init(backgroundColor: PillAssetColor(uiColor: ThemeService.shared().theme.colors.links), + rawRenderingMode: UIImage.RenderingMode.alwaysTemplate.rawValue)) } let data = PillTextAttachmentData(pillType: .room(roomId: roomId), @@ -207,7 +220,10 @@ struct PillProvider { string: room.displayName, matrixId: roomId) } else { - avatar = .asset(named: "link_icon") + avatar = .asset(named: "link_icon", + parameters: .init(backgroundColor: PillAssetColor(uiColor: ThemeService.shared().theme.colors.links), + rawRenderingMode: UIImage.RenderingMode.alwaysTemplate.rawValue)) + } func computeDisplayText(withRoomDisplayName displayName: String?) -> String { diff --git a/Riot/Modules/Pills/PillTextAttachmentData.swift b/Riot/Modules/Pills/PillTextAttachmentData.swift index c83958455..52ef4f852 100644 --- a/Riot/Modules/Pills/PillTextAttachmentData.swift +++ b/Riot/Modules/Pills/PillTextAttachmentData.swift @@ -17,12 +17,33 @@ import Foundation import UIKit +@available (iOS 15.0, *) +struct PillAssetColor: Codable { + var red: CGFloat = 0.0, green: CGFloat = 0.0, blue: CGFloat = 0.0, alpha: CGFloat = 0.0 + + var uiColor: UIColor { + return UIColor(red: red, green: green, blue: blue, alpha: alpha) + } + + init(uiColor: UIColor) { + uiColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha) + } +} + +@available (iOS 15.0, *) +struct PillAssetParameter: Codable { + var tintColor: PillAssetColor? + var backgroundColor: PillAssetColor? + var rawRenderingMode: Int = UIImage.RenderingMode.automatic.rawValue + var padding: CGFloat = 2.0 +} + @available (iOS 15.0, *) enum PillTextAttachmentItem: Codable { case text(String) case avatar(url: String?, string: String?, matrixId: String) case spaceAvatar(url: String?, string: String?, matrixId: String) - case asset(named: String) + case asset(named: String, parameters: PillAssetParameter) } @available (iOS 15.0, *)