diff --git a/Session/Media Viewing & Editing/MessageInfoView.swift b/Session/Media Viewing & Editing/MessageInfoView.swift index 4a23292ca..e03157d30 100644 --- a/Session/Media Viewing & Editing/MessageInfoView.swift +++ b/Session/Media Viewing & Editing/MessageInfoView.swift @@ -19,6 +19,7 @@ struct MessageInfoView: View { var isMessageFailed: Bool { return [.failed, .failedToSync].contains(messageViewModel.state) } + var snapshot: UIView? var dismiss: (() -> Void)? @@ -37,33 +38,39 @@ struct MessageInfoView: View { spacing: 10 ) { // Message bubble snapshot - if let body: String = messageViewModel.body, !body.isEmpty { - let (bubbleBackgroundColor, bubbleTextColor): (ThemeValue, ThemeValue) = ( - messageViewModel.variant == .standardIncoming || - messageViewModel.variant == .standardIncomingDeleted - ) ? - (.messageBubble_incomingBackground, .messageBubble_incomingText) : - (.messageBubble_outgoingBackground, .messageBubble_outgoingText) - - ZStack { - RoundedRectangle(cornerRadius: Self.cornerRadius) - .fill(themeColor: bubbleBackgroundColor) - - Text(body) - .foregroundColor(themeColor: bubbleTextColor) - .padding(.vertical, Values.smallSpacing) - .padding(.horizontal, Values.mediumSpacing) + ZStack { + if let snapshot = self.snapshot { + UIView_SwiftUI(view: snapshot) + } else { + if let body: String = messageViewModel.body, !body.isEmpty { + let (bubbleBackgroundColor, bubbleTextColor): (ThemeValue, ThemeValue) = ( + messageViewModel.variant == .standardIncoming || + messageViewModel.variant == .standardIncomingDeleted + ) ? + (.messageBubble_incomingBackground, .messageBubble_incomingText) : + (.messageBubble_outgoingBackground, .messageBubble_outgoingText) + + RoundedRectangle(cornerRadius: Self.cornerRadius) + .fill(themeColor: bubbleBackgroundColor) + + Text(body) + .foregroundColor(themeColor: bubbleTextColor) + .padding(.vertical, Values.smallSpacing) + .padding(.horizontal, Values.mediumSpacing) + + } } - .frame( - maxWidth: .infinity, - maxHeight: .infinity, - alignment: .topLeading - ) - .fixedSize(horizontal: true, vertical: true) - .padding(.top, Values.smallSpacing) - .padding(.bottom, Values.verySmallSpacing) - .padding(.horizontal, Values.largeSpacing) } + .frame( + maxWidth: .infinity, + maxHeight: .infinity, + alignment: .topLeading + ) + .fixedSize(horizontal: true, vertical: true) + .padding(.top, Values.smallSpacing) + .padding(.bottom, Values.verySmallSpacing) + .padding(.horizontal, Values.largeSpacing) + if isMessageFailed { let (image, statusText, tintColor) = messageViewModel.state.statusIconInfo( diff --git a/SessionUIKit/Utilities/SwiftUI+Utilities.swift b/SessionUIKit/Utilities/SwiftUI+Utilities.swift index 90c32a91a..260a6429d 100644 --- a/SessionUIKit/Utilities/SwiftUI+Utilities.swift +++ b/SessionUIKit/Utilities/SwiftUI+Utilities.swift @@ -35,3 +35,21 @@ extension UIViewController { self.present(toPresent, animated: true, completion: nil) } } + +public struct UIView_SwiftUI: UIViewRepresentable { + public typealias UIViewType = UIView + + private let view: UIView + + public init(view: UIView) { + self.view = view + } + + public func makeUIView(context: Context) -> UIView { + return self.view + } + + public func updateUIView(_ uiView: UIView, context: Context) { + uiView.layoutIfNeeded() + } +}