Name color improvements

This commit is contained in:
Ilya Laktyushin 2023-10-25 13:33:51 +04:00
parent 08b76943c2
commit 7cb8f9739b
8 changed files with 85 additions and 27 deletions

View File

@ -1281,10 +1281,10 @@ public class PeerNameColors: Equatable {
var colors = PeerNameColors.defaultSingleColors
var darkColors: [Int32: Colors] = [:]
if let peerColors = data["peer_colors"] as? [String: [Double]] {
if let peerColors = data["peer_colors"] as? [String: [String]] {
for (key, values) in peerColors {
if let index = Int32(key) {
let colorsArray = values.map { UIColor(rgb: UInt32($0)) }
let colorsArray = values.compactMap { UIColor(hexString: $0) }
if let colorValues = Colors(colors: colorsArray) {
colors[index] = colorValues
}
@ -1292,10 +1292,10 @@ public class PeerNameColors: Equatable {
}
}
if let darkPeerColors = data["dark_peer_colors"] as? [String: [Double]] {
if let darkPeerColors = data["dark_peer_colors"] as? [String: [String]] {
for (key, values) in darkPeerColors {
if let index = Int32(key) {
let colorsArray = values.map { UIColor(rgb: UInt32($0)) }
let colorsArray = values.compactMap { UIColor(hexString: $0) }
if let colorValues = Colors(colors: colorsArray) {
darkColors[index] = colorValues
}

View File

@ -339,10 +339,15 @@ public final class ChatPresentationInterfaceState: Equatable {
}
public struct AccountPeerColor: Equatable {
public var isDashed: Bool
public enum Style {
case solid
case doubleDashed
case tripleDashed
}
public var style: Style
public init(isDashed: Bool) {
self.isDashed = isDashed
public init(style: Style) {
self.style = style
}
}

View File

@ -278,7 +278,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode,
quote: ChatInputTextView.Theme.Quote(
background: mainColor.withMultipliedAlpha(0.1),
foreground: mainColor,
isDashed: textInputView.theme?.quote.isDashed == true
lineStyle: textInputView.theme?.quote.lineStyle ?? .solid
)
)
}

View File

@ -259,18 +259,23 @@ private final class ChatInputTextContainer: NSTextContainer {
public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDelegate, NSTextStorageDelegate {
public final class Theme: Equatable {
public final class Quote: Equatable {
public enum LineStyle {
case solid
case doubleDashed
case tripleDashed
}
public let background: UIColor
public let foreground: UIColor
public let isDashed: Bool
public let lineStyle: LineStyle
public init(
background: UIColor,
foreground: UIColor,
isDashed: Bool
lineStyle: LineStyle
) {
self.background = background
self.foreground = foreground
self.isDashed = isDashed
self.lineStyle = lineStyle
}
public static func ==(lhs: Quote, rhs: Quote) -> Bool {
@ -280,7 +285,7 @@ public final class ChatInputTextView: ChatInputTextViewImpl, NSLayoutManagerDele
if !lhs.foreground.isEqual(rhs.foreground) {
return false
}
if lhs.isDashed != rhs.isDashed {
if lhs.lineStyle != rhs.lineStyle {
return false
}
return true
@ -763,8 +768,8 @@ private final class QuoteBackgroundView: UIView {
self.backgroundView.update(
size: size,
primaryColor: theme.foreground,
secondaryColor: theme.isDashed ? .clear : nil,
thirdColor: nil,
secondaryColor: theme.lineStyle != .solid ? .clear : nil,
thirdColor: theme.lineStyle == .tripleDashed ? .clear : nil,
pattern: nil,
animation: .None
)

View File

@ -222,6 +222,9 @@ public class ChatMessageReplyInfoNode: ASDisplayNode {
if dashSecondaryColor != nil {
secondaryColor = .clear
}
if dashTertiaryColor != nil {
tertiaryColor = .clear
}
}
dustColor = incoming ? arguments.presentationData.theme.theme.chat.message.incoming.secondaryTextColor : arguments.presentationData.theme.theme.chat.message.outgoing.secondaryTextColor
case .standalone:
@ -230,6 +233,9 @@ public class ChatMessageReplyInfoNode: ASDisplayNode {
if dashSecondaryColor != nil {
secondaryColor = .clear
}
if dashTertiaryColor != nil {
tertiaryColor = .clear
}
mainColor = serviceMessageColorComponents(chatTheme: arguments.presentationData.theme.theme.chat, wallpaper: arguments.presentationData.theme.wallpaper).primaryText
dustColor = titleColor

View File

@ -93,24 +93,26 @@ private let dashBackgroundTemplateImage: UIImage = {
}()
private func generateDashTemplateImage(isMonochrome: Bool, isTriple: Bool) -> UIImage {
return generateImage(CGSize(width: radius * 2.0, height: isTriple ? 27.0 : 18.0), rotatedContext: { size, context in
return generateImage(CGSize(width: radius * 2.0, height: 18.0), rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
context.setFillColor(UIColor.white.cgColor)
let dashOffset: CGFloat
if isTriple {
dashOffset = 0.0
dashOffset = isMonochrome ? -2.0 : 0.0
} else {
dashOffset = isMonochrome ? -4.0 : 5.0
}
let dashHeight: CGFloat = isTriple ? 6.0 : 9.0
context.translateBy(x: 0.0, y: dashOffset)
for _ in 0 ..< 2 {
context.move(to: CGPoint(x: 0.0, y: 3.0))
context.addLine(to: CGPoint(x: lineWidth, y: 0.0))
context.addLine(to: CGPoint(x: lineWidth, y: 9.0))
context.addLine(to: CGPoint(x: 0.0, y: 9.0 + 3.0))
context.addLine(to: CGPoint(x: lineWidth, y: dashHeight))
context.addLine(to: CGPoint(x: 0.0, y: dashHeight + 3.0))
context.closePath()
context.fillPath()
@ -133,6 +135,10 @@ private let dashMonochromeTemplateImage: UIImage = {
return generateDashTemplateImage(isMonochrome: true, isTriple: false)
}()
private let dashMonochromeTripleTemplateImage: UIImage = {
return generateDashTemplateImage(isMonochrome: true, isTriple: true)
}()
private func generateGradient(gradientWidth: CGFloat, baseAlpha: CGFloat) -> UIImage {
return generateImage(CGSize(width: gradientWidth, height: 16.0), opaque: false, scale: 1.0, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
@ -334,9 +340,13 @@ private final class LineView: UIView {
}
let templateImage: UIImage
let monochromeTemplateImage: UIImage
if let thirdColor {
let thirdDashBackgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -9.0), size: CGSize(width: radius * 2.0, height: size.height + 18.0))
let thirdDashBackgroundFrame = CGRect(origin: CGPoint(x: 0.0, y: -12.0), size: CGSize(width: radius * 2.0, height: size.height + 18.0))
templateImage = dashOpaqueTripleTemplateImage
monochromeTemplateImage = dashMonochromeTripleTemplateImage
let dashThirdBackgroundView: UIImageView
if let current = self.dashThirdBackgroundView {
dashThirdBackgroundView = current
@ -350,15 +360,18 @@ private final class LineView: UIView {
dashThirdBackgroundView.frame = thirdDashBackgroundFrame
}
if secondaryColor.alpha == 0.0 {
dashThirdBackgroundView.image = templateImage
dashThirdBackgroundView.tintColor = thirdColor
if thirdColor.alpha == 0.0 {
dashThirdBackgroundView.alpha = 0.4
dashThirdBackgroundView.image = monochromeTemplateImage
dashThirdBackgroundView.tintColor = primaryColor
} else {
dashThirdBackgroundView.alpha = 1.0
dashThirdBackgroundView.image = templateImage
dashThirdBackgroundView.tintColor = thirdColor
}
} else {
templateImage = dashOpaqueTemplateImage
monochromeTemplateImage = dashMonochromeTemplateImage
if let dashThirdBackgroundView = self.dashThirdBackgroundView {
self.dashThirdBackgroundView = nil
dashThirdBackgroundView.removeFromSuperview()
@ -367,7 +380,7 @@ private final class LineView: UIView {
if secondaryColor.alpha == 0.0 {
self.backgroundView.alpha = 0.2
dashBackgroundView.image = dashMonochromeTemplateImage
dashBackgroundView.image = monochromeTemplateImage
dashBackgroundView.tintColor = primaryColor
} else {
self.backgroundView.alpha = 1.0

View File

@ -5109,8 +5109,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
if let strongSelf = self {
let isPremium = peerView.peers[peerView.peerId]?.isPremium ?? false
var accountPeerColor: ChatPresentationInterfaceState.AccountPeerColor?
if let nameColor = peerView.peers[peerView.peerId]?.nameColor, strongSelf.context.peerNameColors.get(nameColor).secondary != nil {
accountPeerColor = ChatPresentationInterfaceState.AccountPeerColor(isDashed: true)
if let nameColor = peerView.peers[peerView.peerId]?.nameColor {
let colors = strongSelf.context.peerNameColors.get(nameColor)
var style: ChatPresentationInterfaceState.AccountPeerColor.Style = .solid
if colors.tertiary != nil {
style = .tripleDashed
} else if colors.secondary != nil {
style = .doubleDashed
}
accountPeerColor = ChatPresentationInterfaceState.AccountPeerColor(style: style)
}
strongSelf.updateChatPresentationInterfaceState(animated: false, interactive: false, { state in
return state.updatedIsPremium(isPremium).updatedAccountPeerColor(accountPeerColor)

View File

@ -1045,11 +1045,22 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
var baseFontSize: CGFloat = 17.0
var keyboardAppearance: UIKeyboardAppearance = UIKeyboardAppearance.default
if let presentationInterfaceState = self.presentationInterfaceState {
var lineStyle: ChatInputTextView.Theme.Quote.LineStyle = .solid
if let accountPeerColor = presentationInterfaceState.accountPeerColor {
switch accountPeerColor.style {
case .solid:
lineStyle = .solid
case .doubleDashed:
lineStyle = .doubleDashed
case .tripleDashed:
lineStyle = .tripleDashed
}
}
textInputNode.textView.theme = ChatInputTextView.Theme(
quote: ChatInputTextView.Theme.Quote(
background: presentationInterfaceState.theme.list.itemAccentColor.withMultipliedAlpha(presentationInterfaceState.theme.overallDarkAppearance ? 0.2 : 0.1),
foreground: presentationInterfaceState.theme.list.itemAccentColor,
isDashed: presentationInterfaceState.accountPeerColor?.isDashed == true
lineStyle: lineStyle
)
)
@ -1628,11 +1639,22 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
}
if let textInputNode = self.textInputNode {
var lineStyle: ChatInputTextView.Theme.Quote.LineStyle = .solid
if let accountPeerColor = interfaceState.accountPeerColor {
switch accountPeerColor.style {
case .solid:
lineStyle = .solid
case .doubleDashed:
lineStyle = .doubleDashed
case .tripleDashed:
lineStyle = .tripleDashed
}
}
textInputNode.textView.theme = ChatInputTextView.Theme(
quote: ChatInputTextView.Theme.Quote(
background: interfaceState.theme.list.itemAccentColor.withMultipliedAlpha(interfaceState.theme.overallDarkAppearance ? 0.2 : 0.1),
foreground: interfaceState.theme.list.itemAccentColor,
isDashed: interfaceState.accountPeerColor?.isDashed == true
lineStyle: lineStyle
)
)
}