mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge pull request #275 from RyanRory/placeholder-icon
Placeholder Icon Consistency
This commit is contained in:
commit
6c1780ed61
2 changed files with 6 additions and 2 deletions
|
@ -4,7 +4,11 @@ public final class Identicon : NSObject {
|
|||
|
||||
@objc public static func generatePlaceholderIcon(seed: String, text: String, size: CGFloat) -> UIImage {
|
||||
let icon = PlaceholderIcon(seed: seed)
|
||||
let layer = icon.generateLayer(with: size, text: text.substring(to: 1))
|
||||
var content = text
|
||||
if content.count > 2 && content.hasPrefix("05") {
|
||||
content.removeFirst(2)
|
||||
}
|
||||
let layer = icon.generateLayer(with: size, text: content.substring(to: 1))
|
||||
let rect = CGRect(origin: CGPoint.zero, size: layer.frame.size)
|
||||
let renderer = UIGraphicsImageRenderer(size: rect.size)
|
||||
return renderer.image { layer.render(in: $0.cgContext) }
|
||||
|
|
|
@ -18,7 +18,7 @@ public class PlaceholderIcon {
|
|||
convenience init(seed: String, colours: [UIColor]? = nil) {
|
||||
// Ensure we have a correct hash
|
||||
var hash = seed
|
||||
if !hash.matches("^[0-9A-Fa-f]+$") || hash.count < 12 { hash = seed.sha512() }
|
||||
if (hash.matches("^[0-9A-Fa-f]+$") && hash.count >= 12) { hash = seed.sha512() }
|
||||
|
||||
guard let number = Int(hash.substring(to: 12), radix: 16) else {
|
||||
owsFailDebug("Failed to generate number from seed string: \(seed).")
|
||||
|
|
Loading…
Reference in a new issue