Skip to content

Commit

Permalink
Reworked styles for chat message views
Browse files Browse the repository at this point in the history
Added supporting for borders and gradiented backgrounds
  • Loading branch information
Egor Egorov authored and github-review-helper committed Aug 16, 2023
1 parent c298636 commit d6fe2d7
Show file tree
Hide file tree
Showing 39 changed files with 1,399 additions and 190 deletions.
36 changes: 36 additions & 0 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@
8491AF0A2A78FED700CC3E72 /* GvaGalleryListViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF092A78FED700CC3E72 /* GvaGalleryListViewStyle.swift */; };
8491AF192A7C140F00CC3E72 /* GvaGalleryCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF182A7C140F00CC3E72 /* GvaGalleryCardView.swift */; };
8491AF212A7D1F7900CC3E72 /* ChatView.GvaGallery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF202A7D1F7900CC3E72 /* ChatView.GvaGallery.swift */; };
8491AF0D2A7A9CB900CC3E72 /* Theme.VisitorChatMessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF0C2A7A9CB900CC3E72 /* Theme.VisitorChatMessageStyle.swift */; };
8491AF132A7ACC5400CC3E72 /* Theme.OperatorChatMessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF122A7ACC5400CC3E72 /* Theme.OperatorChatMessageStyle.swift */; };
8491AF152A7ACDB000CC3E72 /* Theme.SystemMessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF142A7ACDB000CC3E72 /* Theme.SystemMessageStyle.swift */; };
8491AF172A7AD1D300CC3E72 /* Theme.ChoiceCardStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF162A7AD1D300CC3E72 /* Theme.ChoiceCardStyle.swift */; };
8491AF1D2A7D01BF00CC3E72 /* Theme.ChatMessageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF1C2A7D01BF00CC3E72 /* Theme.ChatMessageStyle.swift */; };
8491AF1F2A7D027D00CC3E72 /* Theme.ChatTextContentStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF1E2A7D027D00CC3E72 /* Theme.ChatTextContentStyle.swift */; };
8491AF232A8A3EA800CC3E72 /* ChatStyle.Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8491AF222A8A3EA800CC3E72 /* ChatStyle.Deprecated.swift */; };
84A318A12869ECFC00CA1DE5 /* Unavailable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A318A02869ECFC00CA1DE5 /* Unavailable.swift */; };
84CFB7732822700000167258 /* Theme.Button.Accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84CFB7722822700000167258 /* Theme.Button.Accessibility.swift */; };
84D2292B28C61C8D00F64FE7 /* WKNavigationPolicyProvider.CustomResponseCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D2292A28C61C8D00F64FE7 /* WKNavigationPolicyProvider.CustomResponseCard.swift */; };
Expand Down Expand Up @@ -1073,6 +1080,13 @@
8491AF092A78FED700CC3E72 /* GvaGalleryListViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GvaGalleryListViewStyle.swift; sourceTree = "<group>"; };
8491AF182A7C140F00CC3E72 /* GvaGalleryCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GvaGalleryCardView.swift; sourceTree = "<group>"; };
8491AF202A7D1F7900CC3E72 /* ChatView.GvaGallery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatView.GvaGallery.swift; sourceTree = "<group>"; };
8491AF0C2A7A9CB900CC3E72 /* Theme.VisitorChatMessageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.VisitorChatMessageStyle.swift; sourceTree = "<group>"; };
8491AF122A7ACC5400CC3E72 /* Theme.OperatorChatMessageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.OperatorChatMessageStyle.swift; sourceTree = "<group>"; };
8491AF142A7ACDB000CC3E72 /* Theme.SystemMessageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.SystemMessageStyle.swift; sourceTree = "<group>"; };
8491AF162A7AD1D300CC3E72 /* Theme.ChoiceCardStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.ChoiceCardStyle.swift; sourceTree = "<group>"; };
8491AF1C2A7D01BF00CC3E72 /* Theme.ChatMessageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.ChatMessageStyle.swift; sourceTree = "<group>"; };
8491AF1E2A7D027D00CC3E72 /* Theme.ChatTextContentStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.ChatTextContentStyle.swift; sourceTree = "<group>"; };
8491AF222A8A3EA800CC3E72 /* ChatStyle.Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatStyle.Deprecated.swift; sourceTree = "<group>"; };
84A318A02869ECFC00CA1DE5 /* Unavailable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unavailable.swift; sourceTree = "<group>"; };
84CFB7722822700000167258 /* Theme.Button.Accessibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.Button.Accessibility.swift; sourceTree = "<group>"; };
84D2292A28C61C8D00F64FE7 /* WKNavigationPolicyProvider.CustomResponseCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationPolicyProvider.CustomResponseCard.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1938,6 +1952,7 @@
isa = PBXGroup;
children = (
1AC7A7AB2587849200567FF8 /* Alert */,
8491AF0B2A7A9C9200CC3E72 /* Chat */,
75FF151527F4E11000FE7BE2 /* Survey */,
1A60AF7925656E0500E53F53 /* Theme.swift */,
9A19926D27D3BB7800161AAE /* Theme.Mock.swift */,
Expand Down Expand Up @@ -2053,6 +2068,7 @@
C0175A262A67D431001FACDE /* GVA */,
1AC7A7822583B65B00567FF8 /* Cells */,
9AB3402627FCDD92006E0FE2 /* ChatStyle.Accessibility.swift */,
8491AF222A8A3EA800CC3E72 /* ChatStyle.Deprecated.swift */,
1A60AFE725669C5000E53F53 /* ChatStyle.swift */,
1A60AFDC25669A4200E53F53 /* ChatView.swift */,
C0175A1C2A5D4226001FACDE /* ChatView.TableView.swift */,
Expand Down Expand Up @@ -3152,6 +3168,19 @@
path = GalleryCard;
sourceTree = "<group>";
};
8491AF0B2A7A9C9200CC3E72 /* Chat */ = {
isa = PBXGroup;
children = (
8491AF1C2A7D01BF00CC3E72 /* Theme.ChatMessageStyle.swift */,
8491AF0C2A7A9CB900CC3E72 /* Theme.VisitorChatMessageStyle.swift */,
8491AF122A7ACC5400CC3E72 /* Theme.OperatorChatMessageStyle.swift */,
8491AF142A7ACDB000CC3E72 /* Theme.SystemMessageStyle.swift */,
8491AF162A7AD1D300CC3E72 /* Theme.ChoiceCardStyle.swift */,
8491AF1E2A7D027D00CC3E72 /* Theme.ChatTextContentStyle.swift */,
);
path = Chat;
sourceTree = "<group>";
};
84D2292C28C61DE000F64FE7 /* WKNavigationPolicyProvider */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4050,6 +4079,7 @@
9A19926A27D3BA8700161AAE /* ViewFactory.Environment.Interface.swift in Sources */,
1A0EDF8225E8E0150076D1AD /* PopoverViewController.swift in Sources */,
84265E4B298D7B1900D65842 /* CallVisualizer.Coordinator.swift in Sources */,
8491AF172A7AD1D300CC3E72 /* Theme.ChoiceCardStyle.swift in Sources */,
C0D2F07629A4E2CE00803B47 /* ConnectOperatorStyle.Mock.swift in Sources */,
75940987298D38C2008B173A /* VisitorCodeViewModel+Environment.swift in Sources */,
1A60AFBC256682C800E53F53 /* SubFlowCoordinator.swift in Sources */,
Expand Down Expand Up @@ -4089,6 +4119,7 @@
1A0C9A7925C16F9700815406 /* Theme+AlertConfiguration.swift in Sources */,
AF10ED8F29BF849A00E85309 /* UnreadMessageDividerView.swift in Sources */,
1AC8AADD25D419CE00DAFE50 /* VideoStreamView.swift in Sources */,
8491AF152A7ACDB000CC3E72 /* Theme.SystemMessageStyle.swift in Sources */,
1A4AD3C7256E863900468BFB /* ThemeColor.swift in Sources */,
756B8B1E2996BAEA001D2BB2 /* HeaderButton.Props.swift in Sources */,
9A1992DB27D6241400161AAE /* ImageView.Cache.Interface.swift in Sources */,
Expand All @@ -4103,6 +4134,7 @@
846429802A45A1F200943BD6 /* OfferPresenter.swift in Sources */,
1A4AF5D325AEF543002CD0F4 /* AlertViewController+Confirmation.swift in Sources */,
755D187B29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift in Sources */,
8491AF232A8A3EA800CC3E72 /* ChatStyle.Deprecated.swift in Sources */,
1AFB1E7825F8B26800CA460D /* ChatTextContentStyle.swift in Sources */,
1AFB1E7425F8B00B00CA460D /* ChatTextContentView.swift in Sources */,
845876AE282A95DE007AC3DF /* InputQuestionView.Props.Accessibility.swift in Sources */,
Expand All @@ -4124,6 +4156,7 @@
3100D92C296E946600DEC9CE /* SecureConversations.ConfirmationViewController.swift in Sources */,
9A8130BB27D7A41000220BBD /* FileUpload.Environment.Interface.swift in Sources */,
3100D92B296E946600DEC9CE /* SecureConversations+ConfirmationStyle.swift in Sources */,
8491AF132A7ACC5400CC3E72 /* Theme.OperatorChatMessageStyle.swift in Sources */,
845E2F93283FB6D000C04D56 /* Theme.Survey.Accessibility.swift in Sources */,
75940959298D386F008B173A /* UIStackView.Extensions.swift in Sources */,
1A0C9A9125C41AB900815406 /* CallButtonBar.swift in Sources */,
Expand Down Expand Up @@ -4379,6 +4412,7 @@
1AA738AE2578E0D500E1120F /* ConnectAnimationView.swift in Sources */,
754CC61627E2816F005676E9 /* Survey.InputQuestionView.swift in Sources */,
9A1992DF27D62C2E00161AAE /* ImageView.Cache.Mock.swift in Sources */,
8491AF0D2A7A9CB900CC3E72 /* Theme.VisitorChatMessageStyle.swift in Sources */,
1A2DA72D25EF9DD900032611 /* FileUpload.swift in Sources */,
C499A57E26382FAA009962AC /* UnreadMessageIndicatorView.swift in Sources */,
31DB0C01287C2EFC00FB288E /* StaticValues.swift in Sources */,
Expand Down Expand Up @@ -4429,6 +4463,7 @@
75B7BD802A39D5A70060794D /* Layoutable.swift in Sources */,
845876AB282A959C007AC3DF /* SingleChoiceQuestionView.Props.Accessibility.swift in Sources */,
9AB3402327FC859E006E0FE2 /* CallButtonStyle.StateStyle.Accessibility.swift in Sources */,
8491AF1F2A7D027D00CC3E72 /* Theme.ChatTextContentStyle.swift in Sources */,
84D2293C28D1FC4B00F64FE7 /* ChatViewModel+CustomCard.swift in Sources */,
84265DF02983E62100D65842 /* Theme+ScreenSharing.swift in Sources */,
6E9C01AD26D3B8B500EBE1D4 /* OperatorTypingIndicatorView.swift in Sources */,
Expand All @@ -4440,6 +4475,7 @@
7529F2B427E1D503004D3581 /* Survey.swift in Sources */,
84681AA12A66B9F100DD7406 /* SelfSizingCollectionView.swift in Sources */,
1A5F494B25CA86CA003E3678 /* Call.swift in Sources */,
8491AF1D2A7D01BF00CC3E72 /* Theme.ChatMessageStyle.swift in Sources */,
84265E65298D7B2900D65842 /* ScreenSharingView.swift in Sources */,
9A1992ED27D6C19E00161AAE /* FileSystemStorage.Environment.Mock.swift in Sources */,
1AFB1E6825F7AE3C00CA460D /* ChatAttachment.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions GliaWidgets/ColorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public enum ColorType: Equatable {
return false
}
}

var color: UIColor {
switch self {
case let .fill(color):
return color
case let .gradient(colors):
return UIColor(cgColor: colors.first ?? .clear)
}
}
}
8 changes: 7 additions & 1 deletion GliaWidgets/Sources/Extensions/UIColor+Hex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension UIColor {
self.init(red: components.R, green: components.G, blue: components.B, alpha: components.a)
}

func toHex(alpha: Bool = false) -> String? {
func toHex(alpha: Bool = true) -> String? {
guard let components = cgColor.components, components.count >= 3 else {
return nil
}
Expand All @@ -48,3 +48,9 @@ extension UIColor {
}
}
}

extension CGColor {
static var clear: CGColor {
UIColor.clear.cgColor
}
}
67 changes: 67 additions & 0 deletions GliaWidgets/Sources/Theme/Chat/Theme.ChatMessageStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import UIKit

extension Theme {
/// Internal base style of a chat message.
struct ChatMessageStyle {
/// Style of the message text.
let text: Text
/// Style of the message background.
let background: Layer
/// Style of the image content.
let imageFile: ChatImageFileContentStyle
/// Style of the image content.
let fileDownload: ChatFileDownloadStyle
/// Accessibility related properties.
let accessibility: Accessibility

///
/// - Parameters:
/// - text: Style of the message text.
/// - background: Style of the message background.
/// - imageFile: Style of the image content.
/// - fileDownload: Style of the downloadable file content.
/// - accessibility: Accessibility related properties.
///
init(
text: Text,
background: Layer,
imageFile: ChatImageFileContentStyle,
fileDownload: ChatFileDownloadStyle,
accessibility: Accessibility = .unsupported
) {
self.text = text
self.background = background
self.imageFile = imageFile
self.fileDownload = fileDownload
self.accessibility = accessibility
}
}
}

extension Theme.ChatMessageStyle {
/// Accessibility properties for ChatMessageStyle.
struct Accessibility: Equatable {
/// Accessibility value.
var value: String
/// Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
var isFontScalingEnabled: Bool

///
/// - Parameters:
/// - value: Accessibility value.
/// - isFontScalingEnabled: Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
init(
value: String = "",
isFontScalingEnabled: Bool
) {
self.value = value
self.isFontScalingEnabled = isFontScalingEnabled
}

/// Accessibility is not supported intentionally.
static let unsupported = Self(
value: "",
isFontScalingEnabled: false
)
}
}
58 changes: 58 additions & 0 deletions GliaWidgets/Sources/Theme/Chat/Theme.ChatTextContentStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import UIKit

public extension Theme {
/// Style of a text message.
struct ChatTextContentStyle {
/// Style of the message text.
public var text: Text
/// Style of the content view.
public var background: Layer
/// Accessibility related properties.
public var accessibility: Accessibility

///
/// - Parameters:
/// - text: Style of the message text.
/// - background: Style of the content view.
/// - accessibility: Accessibility related properties.
///
public init(
text: Text,
background: Layer,
accessibility: Accessibility = .unsupported
) {
self.text = text
self.background = background
self.accessibility = accessibility
}
}
}

extension Theme.ChatTextContentStyle {
/// Accessibility properties for ChatTextContentStyle.
public struct Accessibility: Equatable {
/// Accessibility value.
public var value: String

/// Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
public var isFontScalingEnabled: Bool

///
/// - Parameters:
/// - value: Accessibility value.
/// - isFontScalingEnabled: Flag that provides font dynamic type by setting `adjustsFontForContentSizeCategory` for component that supports it.
public init(
value: String = "",
isFontScalingEnabled: Bool
) {
self.value = value
self.isFontScalingEnabled = isFontScalingEnabled
}

/// Accessibility is not supported intentionally.
public static let unsupported = Self(
value: "",
isFontScalingEnabled: false
)
}
}
Loading

0 comments on commit d6fe2d7

Please sign in to comment.