mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Avatars and Usernames color change (#1610)
* avatars and username color change * force a replacement for the notification placeholders * updated also the plain style * Update project.yml Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> * changelog * UI tests updated --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
@@ -30,14 +30,7 @@ public struct ElementColors {
|
||||
|
||||
@available(swift, deprecated: 5.0, message: "Use textActionAccent/iconAccentTertiary from Compound.")
|
||||
public var brand: Color { colors.accent }
|
||||
|
||||
public var contentAndAvatars: [Color] { colors.contentAndAvatars }
|
||||
|
||||
public func avatarBackground(for contentId: String) -> Color {
|
||||
let colorIndex = Int(contentId.hashCode % Int32(contentAndAvatars.count))
|
||||
return contentAndAvatars[colorIndex % contentAndAvatars.count]
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Temp
|
||||
|
||||
/// The background colour of a row in a Form or grouped List.
|
||||
@@ -45,17 +38,3 @@ public struct ElementColors {
|
||||
/// This colour will be removed once Compound form styles are used everywhere.
|
||||
public var formRowBackground = Color.compound.bgCanvasDefaultLevel1
|
||||
}
|
||||
|
||||
private extension String {
|
||||
/// Calculates a numeric hash same as Element Web
|
||||
/// See original function here https://github.com/matrix-org/matrix-react-sdk/blob/321dd49db4fbe360fc2ff109ac117305c955b061/src/utils/FormattingUtils.js#L47
|
||||
var hashCode: Int32 {
|
||||
var hash: Int32 = 0
|
||||
|
||||
for character in self {
|
||||
let shiftedHash = hash << 5
|
||||
hash = shiftedHash.subtractingReportingOverflow(hash).partialValue + Int32(character.unicodeScalars[character.unicodeScalars.startIndex].value)
|
||||
}
|
||||
return abs(hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user