From 4826da08254bda267f2350c548a202545141ea5b Mon Sep 17 00:00:00 2001 From: Levitating Pineapple Date: Sat, 24 Aug 2024 16:47:19 +0300 Subject: [PATCH] rename --- .../Chat/ChatItem/CIGroupInvitationView.swift | 2 +- .../Views/Chat/ChatItem/FramedItemView.swift | 2 +- .../Chat/ChatItem/MarkedDeletedItemView.swift | 2 +- .../Views/Helpers/ChatItemClipShape.swift | 48 ++++++++++--------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ChatItem/CIGroupInvitationView.swift b/apps/ios/Shared/Views/Chat/ChatItem/CIGroupInvitationView.swift index 7ccd07b027..d793492c1f 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/CIGroupInvitationView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/CIGroupInvitationView.swift @@ -70,7 +70,7 @@ struct CIGroupInvitationView: View { } .padding(.horizontal, 12) .padding(.vertical, 6) - .modifier(ChatBubblePadding(chatItem: chatItem)) + .modifier(ChatTailPadding(chatItem: chatItem)) .background(chatItemFrameColor(chatItem, theme)) .textSelection(.disabled) .onPreferenceChange(DetermineWidth.Key.self) { frameWidth = $0 } diff --git a/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift b/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift index 4060840723..4e52bfc1cd 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift @@ -72,7 +72,7 @@ struct FramedItemView: View { .accessibilityLabel("") } } - .modifier(ChatBubblePadding(chatItem: chatItem)) + .modifier(ChatTailPadding(chatItem: chatItem)) .background(chatItemFrameColorMaybeImageOrVideo(chatItem, theme)) .onPreferenceChange(DetermineWidth.Key.self) { msgWidth = $0 } diff --git a/apps/ios/Shared/Views/Chat/ChatItem/MarkedDeletedItemView.swift b/apps/ios/Shared/Views/Chat/ChatItem/MarkedDeletedItemView.swift index b3ba6e44b5..171476f2de 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/MarkedDeletedItemView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/MarkedDeletedItemView.swift @@ -22,7 +22,7 @@ struct MarkedDeletedItemView: View { .foregroundColor(theme.colors.secondary) .padding(.horizontal, 12) .padding(.vertical, 6) - .modifier(ChatBubblePadding(chatItem: chatItem)) + .modifier(ChatTailPadding(chatItem: chatItem)) .background(chatItemFrameColor(chatItem, theme)) .textSelection(.disabled) } diff --git a/apps/ios/Shared/Views/Helpers/ChatItemClipShape.swift b/apps/ios/Shared/Views/Helpers/ChatItemClipShape.swift index 34244ca05f..b2219b285e 100644 --- a/apps/ios/Shared/Views/Helpers/ChatItemClipShape.swift +++ b/apps/ios/Shared/Views/Helpers/ChatItemClipShape.swift @@ -15,12 +15,12 @@ import SimpleXChat /// by retaining pill shape, even when ``ChatItem``'s height is less that twice its corner radius struct ChatItemClipped: ViewModifier { @AppStorage(DEFAULT_CHAT_ITEM_ROUNDNESS) private var roundness = defaultChatItemRoundness - private let shapePath: ChatBubble.ShapePath + private let itemShape: ChatItemShape - init() { shapePath = .roundRect(maxRadius: 8) } + init() { itemShape = .roundRect(maxRadius: 8) } init(_ chatItem: ChatItem, isTailVisible: Bool) { - shapePath = switch chatItem.content { + itemShape = switch chatItem.content { case .sndMsgContent, .rcvMsgContent, @@ -35,7 +35,9 @@ struct ChatItemClipped: ViewModifier { .rcvBlocked, .invalidJSON: .bubble( padding: ChatBubble.paddingEdge(for: chatItem), - isTailVisible: Self.hidesTail(chatItem.content.msgContent) ? false : isTailVisible + isTailVisible: Self.hidesTail(chatItem.content.msgContent) + ? false + : isTailVisible ) default: .roundRect(maxRadius: 8) } @@ -51,7 +53,7 @@ struct ChatItemClipped: ViewModifier { } func body(content: Content) -> some View { - let shape = ChatBubble(roundness: roundness, shapePath: shapePath) + let shape = ChatBubble(roundness: roundness, shapePath: itemShape) content .contentShape(.dragPreview, shape) .contentShape(.contextMenuPreview, shape) @@ -59,27 +61,11 @@ struct ChatItemClipped: ViewModifier { } } -struct ChatBubblePadding: ViewModifier { - let chatItem: ChatItem - - func body(content: Content) -> some View { - content.padding( - chatItem.chatDir.sent ? .trailing : .leading, - ChatBubble.tailSize - ) - } -} - struct ChatBubble: Shape { - enum ShapePath { - case bubble(padding: HorizontalEdge, isTailVisible: Bool) - case roundRect(maxRadius: Double) - } - static let tailSize: Double = 8 static let maxRadius: Double = 16 - let roundness: Double - let shapePath: ShapePath + fileprivate let roundness: Double + fileprivate let shapePath: ChatItemShape func path(in rect: CGRect) -> Path { switch shapePath { @@ -141,3 +127,19 @@ struct ChatBubble: Shape { chatItem.chatDir.sent ? .trailing : .leading } } + +struct ChatTailPadding: ViewModifier { + let chatItem: ChatItem + + func body(content: Content) -> some View { + content.padding( + chatItem.chatDir.sent ? .trailing : .leading, + ChatBubble.tailSize + ) + } +} + +fileprivate enum ChatItemShape { + case bubble(padding: HorizontalEdge, isTailVisible: Bool) + case roundRect(maxRadius: Double) +}