Support custom themes

This commit is contained in:
Ali
2021-12-20 02:09:50 +04:00
parent 468f740d54
commit b4382b6fc0
2 changed files with 61 additions and 9 deletions

View File

@@ -250,10 +250,18 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti
incoming: chat.message.incoming.withUpdated(
bubble: chat.message.incoming.bubble.withUpdated(
withWallpaper: chat.message.incoming.bubble.withWallpaper.withUpdated(
stroke: incomingBubbleStrokeColor
stroke: incomingBubbleStrokeColor,
reactionInactiveBackground: accentColor?.withMultipliedAlpha(0.1),
reactionInactiveForeground: accentColor,
reactionActiveBackground: accentColor,
reactionActiveForeground: .clear
),
withoutWallpaper: chat.message.incoming.bubble.withoutWallpaper.withUpdated(
stroke: incomingBubbleStrokeColor
stroke: incomingBubbleStrokeColor,
reactionInactiveBackground: accentColor?.withMultipliedAlpha(0.1),
reactionInactiveForeground: accentColor,
reactionActiveBackground: accentColor,
reactionActiveForeground: .clear
)
),
linkHighlightColor: accentColor?.withAlphaComponent(0.3),
@@ -278,12 +286,20 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti
withWallpaper: chat.message.outgoing.bubble.withWallpaper.withUpdated(
fill: outgoingBubbleFillColors,
highlightedFill: outgoingBubbleHighlightedFill,
stroke: outgoingBubbleStrokeColor
stroke: outgoingBubbleStrokeColor,
reactionInactiveBackground: outgoingControlColor?.withMultipliedAlpha(0.1),
reactionInactiveForeground: outgoingControlColor,
reactionActiveBackground: outgoingControlColor,
reactionActiveForeground: .clear
),
withoutWallpaper: chat.message.outgoing.bubble.withoutWallpaper.withUpdated(
fill: outgoingBubbleFillColors,
highlightedFill: outgoingBubbleHighlightedFill,
stroke: outgoingBubbleStrokeColor
stroke: outgoingBubbleStrokeColor,
reactionInactiveBackground: outgoingControlColor?.withMultipliedAlpha(0.1),
reactionInactiveForeground: outgoingControlColor,
reactionActiveBackground: outgoingControlColor,
reactionActiveForeground: .clear
)
),
primaryTextColor: outgoingPrimaryTextColor,

View File

@@ -1101,6 +1101,7 @@ extension PresentationThemeBubbleColorComponents: Codable {
case reactionInactiveFg
case reactionActiveBg
case reactionActiveFg
case __workaroundNonexistingKey
}
public convenience init(from decoder: Decoder) throws {
@@ -1121,16 +1122,51 @@ extension PresentationThemeBubbleColorComponents: Codable {
fill = [fillColor, gradientColor]
}
let fallbackKeyPrefix: String
if codingPath.hasPrefix("chat.message.incoming.") {
fallbackKeyPrefix = "chat.message.incoming."
} else {
fallbackKeyPrefix = "chat.message.outgoing."
}
let reactionInactiveBackground: UIColor
if let color = try? decodeColor(values, .reactionInactiveBg) {
reactionInactiveBackground = color
} else {
reactionInactiveBackground = (try decodeColor(values, .__workaroundNonexistingKey, fallbackKey: "\(fallbackKeyPrefix).accentControl")).withMultipliedAlpha(0.1)
}
let reactionInactiveForeground: UIColor
if let color = try? decodeColor(values, .reactionInactiveFg) {
reactionInactiveForeground = color
} else {
reactionInactiveForeground = try decodeColor(values, .__workaroundNonexistingKey, fallbackKey: "\(fallbackKeyPrefix).accentControl")
}
let reactionActiveBackground: UIColor
if let color = try? decodeColor(values, .reactionActiveBg) {
reactionActiveBackground = color
} else {
reactionActiveBackground = try decodeColor(values, .__workaroundNonexistingKey, fallbackKey: "\(fallbackKeyPrefix).accentControl")
}
let reactionActiveForeground: UIColor
if let color = try? decodeColor(values, .reactionActiveFg) {
reactionActiveForeground = color
} else {
reactionActiveForeground = .clear
}
self.init(
fill: fill,
highlightedFill: try decodeColor(values, .highlightedBg),
stroke: try decodeColor(values, .stroke),
shadow: try? values.decode(PresentationThemeBubbleShadow.self, forKey: .shadow),
reactionInactiveBackground: try decodeColor(values, .reactionInactiveBg),
reactionInactiveForeground: try decodeColor(values, .reactionInactiveFg),
reactionActiveBackground: try decodeColor(values, .reactionActiveBg),
reactionActiveForeground: try decodeColor(values, .reactionActiveFg)
reactionInactiveBackground: reactionInactiveBackground,
reactionInactiveForeground: reactionInactiveForeground,
reactionActiveBackground: reactionActiveBackground,
reactionActiveForeground: reactionActiveForeground
)
}