WIP: fix snapshot

This commit is contained in:
Ryan Zhao 2022-06-30 17:20:11 +10:00
parent 23563467b6
commit e8518188ac
2 changed files with 18 additions and 1 deletions

View File

@ -513,7 +513,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
// Show the context menu if applicable
guard let index = viewItems.firstIndex(where: { $0 === viewItem }),
let cell = messagesTableView.cellForRow(at: IndexPath(row: index, section: 0)) as? VisibleMessageCell,
let snapshot = cell.bubbleView.snapshotView(afterScreenUpdates: false), contextMenuWindow == nil,
let snapshot = cell.snapshot(afterScreenUpdates: false), contextMenuWindow == nil,
!ContextMenuVC.actions(for: viewItem, delegate: self).isEmpty else { return }
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
let frame = cell.convert(cell.bubbleView.frame, to: UIApplication.shared.keyWindow!)

View File

@ -1,3 +1,4 @@
import UIKit
final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
private var isHandlingLongPress: Bool = false
@ -806,3 +807,19 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
return result
}
}
extension VisibleMessageCell {
public func snapshot(afterScreenUpdates afterUpdates: Bool) -> UIView? {
let labelForRendering = UILabel()
labelForRendering.numberOfLines = 0
labelForRendering.backgroundColor = self.bubbleView.backgroundColor
if let bodyTextView = self.bodyTextView {
labelForRendering.attributedText = bodyTextView.attributedText
self.snContentView.addSubview(labelForRendering)
labelForRendering.frame = self.snContentView.convert(bodyTextView.frame, to: self.snContentView)
}
let snapshot = self.bubbleView.snapshotView(afterScreenUpdates: true)
labelForRendering.removeFromSuperview()
return snapshot
}
}