Tune outgoing bubble highlight color

This commit is contained in:
Ilya Laktyushin 2023-03-03 14:30:08 +04:00
parent b0256a8f5f
commit 4f5d1445ae
5 changed files with 67 additions and 9 deletions

View File

@ -218,12 +218,13 @@ public class ChatMessageBackground: ASDisplayNode {
}
let outlineImage: UIImage?
var isIncoming = false
if hasWallpaper {
switch type {
case .none:
outlineImage = nil
case let .incoming(mergeType):
isIncoming = true
switch mergeType {
case .None:
outlineImage = graphics.chatMessageBackgroundIncomingOutlineImage
@ -307,7 +308,7 @@ public class ChatMessageBackground: ASDisplayNode {
}
self.imageNode.image = image
if highlighted && maskMode, let backdropNode = self.backdropNode, backdropNode.hasImage {
if highlighted && maskMode, let backdropNode = self.backdropNode, backdropNode.hasImage && isIncoming {
self.imageNode.layer.compositingFilter = "overlayBlendMode"
self.imageNode.alpha = 1.0

View File

@ -158,6 +158,24 @@ public extension UIColor {
}
}
var brightness: CGFloat {
var hue: CGFloat = 0.0
var saturation: CGFloat = 0.0
var brightness: CGFloat = 0.0
var alpha: CGFloat = 0.0
self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
return brightness
}
var saturation: CGFloat {
var hue: CGFloat = 0.0
var saturation: CGFloat = 0.0
var brightness: CGFloat = 0.0
var alpha: CGFloat = 0.0
self.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
return saturation
}
func withMultipliedBrightnessBy(_ factor: CGFloat) -> UIColor {
var hue: CGFloat = 0.0
var saturation: CGFloat = 0.0
@ -202,6 +220,26 @@ public extension UIColor {
return self
}
func multipliedWith(_ other: UIColor) -> UIColor {
var r1: CGFloat = 0.0
var r2: CGFloat = 0.0
var g1: CGFloat = 0.0
var g2: CGFloat = 0.0
var b1: CGFloat = 0.0
var b2: CGFloat = 0.0
var a1: CGFloat = 0.0
var a2: CGFloat = 0.0
if self.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) &&
other.getRed(&r2, green: &g2, blue: &b2, alpha: &a2)
{
let r = r1 * r2
let g = g1 * g2
let b = b1 * b2
return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
return self
}
func blitOver(_ other: UIColor, alpha: CGFloat) -> UIColor {
let alpha = min(1.0, max(0.0, alpha))

View File

@ -2726,7 +2726,7 @@ public final class PremiumIntroScreen: ViewControllerComponentContainer {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
if modal {
let cancelItem = UIBarButtonItem(title: presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed))
let cancelItem = UIBarButtonItem(title: presentationData.strings.Common_Close, style: .plain, target: self, action: #selector(self.cancelPressed))
self.navigationItem.setLeftBarButton(cancelItem, animated: false)
self.navigationPresentation = .modal
} else {

View File

@ -174,6 +174,16 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit
}
}
var highlightedBubbleFillColor: UIColor?
if let outgoingBubbleFillColors {
let middleBubbleFillColor = outgoingBubbleFillColors[Int(floor(Float(outgoingBubbleFillColors.count) / 2))]
if middleBubbleFillColor.brightness > 0.98 {
highlightedBubbleFillColor = middleBubbleFillColor.withMultiplied(hue: 1.0, saturation: 0.87, brightness: 1.0)
} else {
highlightedBubbleFillColor = middleBubbleFillColor.withMultiplied(hue: 1.0, saturation: 1.1, brightness: 1.121)
}
}
chat = chat.withUpdated(
defaultWallpaper: defaultWallpaper,
animateMessageColors: animateBubbleColors,
@ -223,7 +233,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit
bubble: chat.message.outgoing.bubble.withUpdated(
withWallpaper: chat.message.outgoing.bubble.withWallpaper.withUpdated(
fill: outgoingBubbleFillColors,
highlightedFill: outgoingBubbleFillColors?.first?.withMultipliedBrightnessBy(1.421),
highlightedFill: highlightedBubbleFillColor,
stroke: .clear,
reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.12),
reactionInactiveForeground: UIColor(rgb: 0xffffff),
@ -234,7 +244,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit
),
withoutWallpaper: chat.message.outgoing.bubble.withoutWallpaper.withUpdated(
fill: outgoingBubbleFillColors,
highlightedFill: outgoingBubbleFillColors?.first?.withMultipliedBrightnessBy(1.421),
highlightedFill: highlightedBubbleFillColor,
stroke: .clear,
reactionInactiveBackground: UIColor(rgb: 0xffffff, alpha: 0.12),
reactionInactiveForeground: UIColor(rgb: 0xffffff),

View File

@ -168,7 +168,16 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti
outgoingBubbleStrokeColor = .clear
}
outgoingBubbleHighlightedFill = outgoingBubbleFillColors?.first?.withMultiplied(hue: 1.00, saturation: 1.589, brightness: 0.96)
if let outgoingBubbleFillColors {
let middleBubbleFillColor = outgoingBubbleFillColors[Int(floor(Float(outgoingBubbleFillColors.count - 1) / 2))]
if middleBubbleFillColor.lightness < 0.85 {
outgoingBubbleHighlightedFill = middleBubbleFillColor.multipliedWith(middleBubbleFillColor).withMultiplied(hue: 1.0, saturation: 0.6, brightness: 1.0)
} else if middleBubbleFillColor.lightness > 0.97 {
outgoingBubbleHighlightedFill = middleBubbleFillColor.withMultiplied(hue: 1.00, saturation: 2.359, brightness: 0.99)
} else {
outgoingBubbleHighlightedFill = middleBubbleFillColor.withMultiplied(hue: 1.00, saturation: 1.589, brightness: 0.99)
}
}
let lightnessColor = UIColor.average(of: bubbleColors.map(UIColor.init(rgb:)))
if lightnessColor.lightness > 0.705 {
@ -622,7 +631,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio
bubble: PresentationThemeBubbleColor(
withWallpaper: PresentationThemeBubbleColorComponents(
fill: [UIColor(rgb: 0xe1ffc7)],
highlightedFill: UIColor(rgb: 0xc8ffa6),
highlightedFill: UIColor(rgb: 0xbaff93),
stroke: bubbleStrokeColor,
shadow: nil,
reactionInactiveBackground: UIColor(rgb: 0x2DA32F).withMultipliedAlpha(0.12),
@ -634,7 +643,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio
),
withoutWallpaper: PresentationThemeBubbleColorComponents(
fill: [UIColor(rgb: 0xe1ffc7)],
highlightedFill: UIColor(rgb: 0xc8ffa6),
highlightedFill: UIColor(rgb: 0xbaff93),
stroke: bubbleStrokeColor,
shadow: nil,
reactionInactiveBackground: UIColor(rgb: 0x2DA32F).withMultipliedAlpha(0.12),