WIP: fix original message rendering issues

pull/874/head
ryanzhao 2 years ago
parent f4b17c0f06
commit 3e0a4dec20

@ -19,6 +19,7 @@ struct MessageInfoView: View {
var isMessageFailed: Bool { var isMessageFailed: Bool {
return [.failed, .failedToSync].contains(messageViewModel.state) return [.failed, .failedToSync].contains(messageViewModel.state)
} }
var snapshot: UIView?
var dismiss: (() -> Void)? var dismiss: (() -> Void)?
@ -37,33 +38,39 @@ struct MessageInfoView: View {
spacing: 10 spacing: 10
) { ) {
// Message bubble snapshot // Message bubble snapshot
if let body: String = messageViewModel.body, !body.isEmpty { ZStack {
let (bubbleBackgroundColor, bubbleTextColor): (ThemeValue, ThemeValue) = ( if let snapshot = self.snapshot {
messageViewModel.variant == .standardIncoming || UIView_SwiftUI(view: snapshot)
messageViewModel.variant == .standardIncomingDeleted } else {
) ? if let body: String = messageViewModel.body, !body.isEmpty {
(.messageBubble_incomingBackground, .messageBubble_incomingText) : let (bubbleBackgroundColor, bubbleTextColor): (ThemeValue, ThemeValue) = (
(.messageBubble_outgoingBackground, .messageBubble_outgoingText) messageViewModel.variant == .standardIncoming ||
messageViewModel.variant == .standardIncomingDeleted
ZStack { ) ?
RoundedRectangle(cornerRadius: Self.cornerRadius) (.messageBubble_incomingBackground, .messageBubble_incomingText) :
.fill(themeColor: bubbleBackgroundColor) (.messageBubble_outgoingBackground, .messageBubble_outgoingText)
Text(body) RoundedRectangle(cornerRadius: Self.cornerRadius)
.foregroundColor(themeColor: bubbleTextColor) .fill(themeColor: bubbleBackgroundColor)
.padding(.vertical, Values.smallSpacing)
.padding(.horizontal, Values.mediumSpacing) 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 { if isMessageFailed {
let (image, statusText, tintColor) = messageViewModel.state.statusIconInfo( let (image, statusText, tintColor) = messageViewModel.state.statusIconInfo(

@ -35,3 +35,21 @@ extension UIViewController {
self.present(toPresent, animated: true, completion: nil) 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()
}
}

Loading…
Cancel
Save