Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unified customization for SC bottom banner #1090

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension RemoteConfiguration {
let newMessagesDividerText: Text?
let systemMessage: MessageBalloon?
let gva: Gva?
let secureMessaging: SecureConversations?
}

struct Gva: Codable {
Expand Down
3 changes: 2 additions & 1 deletion GliaWidgets/Sources/Theme/Theme+Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ extension Theme {
let secureMessagingBottomBannerStyle = SecureMessagingBottomBannerViewStyle(
message: Localization.SecureMessaging.Chat.Banner.bottom,
font: font.caption,
textStyle: .caption1,
textColor: color.baseNormal,
backgroundColor: color.baseNeutral,
backgroundColor: .fill(color: color.baseNeutral),
dividerColor: color.baseShade
)

Expand Down
14 changes: 14 additions & 0 deletions GliaWidgets/Sources/View/Chat/ChatStyle.RemoteConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ extension ChatStyle {
text: configuration?.newMessagesDividerText,
assetBuilder: assetsBuilder
)
applyAdditionalStyles(
configuration: configuration,
assetsBuilder: assetsBuilder
)
}

private func applyAdditionalStyles(
configuration: RemoteConfiguration.Chat?,
assetsBuilder: RemoteConfiguration.AssetsBuilder
) {
systemMessageStyle.apply(
configuration: configuration?.systemMessage,
assetsBuilder: assetsBuilder
Expand All @@ -63,6 +73,10 @@ extension ChatStyle {
configuration: configuration?.gva,
assetBuilder: assetsBuilder
)
secureMessagingBottomBannerStyle.apply(
configuration: configuration?.secureMessaging,
assetBuilder: assetsBuilder
)
applyBackground(color: configuration?.background?.color)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class SecureMessagingBottomBannerView: UIView {
private func renderProps() {
label.text = props.style.message
label.textColor = props.style.textColor
backgroundColor = props.style.backgroundColor
backgroundColor = props.style.backgroundColor.color
label.font = props.style.font
isHidden = props.isHidden
divider.backgroundColor = props.style.dividerColor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
// TODO: Unified customization will be implemented with MOB-3717
import UIKit

import Foundation
extension SecureMessagingBottomBannerViewStyle {
mutating func apply(
configuration: RemoteConfiguration.SecureConversations?,
assetBuilder: RemoteConfiguration.AssetsBuilder
) {
configuration?.bottomBannerBackground?.color.unwrap {
switch $0.type {
case .fill:
$0.value
.map { UIColor(hex: $0) }
.first
.unwrap { backgroundColor = .fill(color: $0) }
case .gradient:
let colors = $0.value.convertToCgColors()
backgroundColor = .gradient(colors: colors)
}
}

configuration?.topBannerDividerColor?.value
.map { UIColor(hex: $0) }
.first
.unwrap { dividerColor = $0 }

configuration?.bottomBannerText?.foreground?.value
.map { UIColor(hex: $0) }
.first
.unwrap { textColor = $0 }

UIFont.convertToFont(
uiFont: assetBuilder.fontBuilder(configuration?.bottomBannerText?.font),
textStyle: textStyle
)
.unwrap { font = $0 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,46 @@ public struct SecureMessagingBottomBannerViewStyle: Equatable {
public var message: String
/// Font of banner message.
public var font: UIFont
/// Style of the text of the banner message.
public var textStyle: UIFont.TextStyle
/// Color of the text of the banner message.
public var textColor: UIColor
/// Color of the banner background.
public var backgroundColor: UIColor
public var backgroundColor: ColorType
/// Color of the banner divider.
public var dividerColor: UIColor

/// - Parameters:
/// - message: Text of the banner message.
/// - font: Font of banner message.
/// - textStyle: Style of the text of the banner message.
/// - textColor: Color of the text of the banner message.
/// - backgroundColor: Color of the banner background.
/// - dividerColor: Color of the banner divider.
public init(
message: String,
font: UIFont,
textStyle: UIFont.TextStyle,
textColor: UIColor,
backgroundColor: UIColor,
backgroundColor: ColorType,
dividerColor: UIColor
) {
self.message = message
self.font = font
self.textColor = textColor
self.backgroundColor = backgroundColor
self.dividerColor = dividerColor
self.textStyle = textStyle
}
}

extension SecureMessagingBottomBannerViewStyle {
static let initial = Self(
message: "",
font: .preferredFont(forTextStyle: .caption1),
textStyle: .caption1,
textColor: .label,
backgroundColor: .red,
backgroundColor: .fill(color: .red),
dividerColor: .yellow
)
}
4 changes: 3 additions & 1 deletion GliaWidgetsTests/Sources/ChatView/ChatStyle.Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,15 @@ extension SecureMessagingBottomBannerViewStyle {
static func mock(
message: String = Localization.SecureMessaging.Chat.Banner.bottom,
font: UIFont = Theme().chat.secureMessagingBottomBannerStyle.font,
textStyle: UIFont.TextStyle = Theme().chat.secureMessagingBottomBannerStyle.textStyle,
textColor: UIColor = Theme().chat.secureMessagingBottomBannerStyle.textColor,
backgroundColor: UIColor = Theme().chat.secureMessagingBottomBannerStyle.backgroundColor,
backgroundColor: ColorType = Theme().chat.secureMessagingBottomBannerStyle.backgroundColor,
dividerColor: UIColor = Theme().chat.secureMessagingBottomBannerStyle.dividerColor
) -> Self {
.init(
message: message,
font: font,
textStyle: textStyle,
textColor: textColor,
backgroundColor: backgroundColor,
dividerColor: dividerColor
Expand Down
Loading