mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +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:
@@ -12,7 +12,7 @@ let package = Package(
|
||||
.library(name: "DesignKit", targets: ["DesignKit"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/vector-im/compound-ios", revision: "50bb7cf313bd1ad17201fc7e4c1184737a0f44c2"),
|
||||
.package(url: "https://github.com/vector-im/compound-ios", revision: "71b0c887880de639c854600a9ada6b5bcc93c719"),
|
||||
.package(url: "https://github.com/vector-im/element-design-tokens", exact: "0.0.3"),
|
||||
.package(url: "https://github.com/siteline/SwiftUI-Introspect", from: "0.9.0")
|
||||
],
|
||||
|
||||
@@ -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