Add instant view arbitrary text selection

This commit is contained in:
Ilya Laktyushin
2020-04-27 16:47:38 +04:00
parent cfd5419005
commit a941fe6abf
4 changed files with 678 additions and 54 deletions

View File

@@ -17,6 +17,7 @@ import ShareController
import OpenInExternalAppUI
import AppBundle
import LocalizedPeerData
import TextSelectionNode
private let deleteImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/MessageSelectionTrash"), color: .white)
private let actionImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/MessageSelectionAction"), color: .white)
@@ -119,6 +120,7 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll
private let scrollNode: ASScrollNode
private let textNode: ImmediateTextNode
private var textSelectionNode: TextSelectionNode?
private let authorNameNode: ASTextNode
private let dateNode: ASTextNode
private let backwardButton: HighlightableButtonNode
@@ -360,6 +362,23 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll
}
}
self.statusButtonNode.addTarget(self, action: #selector(self.statusPressed), forControlEvents: .touchUpInside)
let accentColor = presentationData.theme.list.itemAccentColor
let textSelectionNode = TextSelectionNode(theme: TextSelectionTheme(selection: accentColor.withAlphaComponent(0.2), knob: accentColor), strings: presentationData.strings, textNode: self.textNode, updateIsActive: { [weak self] value in
// self?.updateIsTextSelectionActive?(value)
}, present: { [weak self] c, a in
// self?.item?.controllerInteraction.presentGlobalOverlayController(c, a)
}, rootNode: self, performAction: { [weak self] text, action in
// guard let strongSelf = self, let item = strongSelf.item else {
// return
// }
// item.controllerInteraction.performTextSelectionAction(item.message.stableId, text, action)
})
self.textSelectionNode = textSelectionNode
self.scrollNode.addSubnode(textSelectionNode)
self.scrollNode.insertSubnode(textSelectionNode.highlightAreaNode, belowSubnode: self.textNode)
textSelectionNode.frame = self.textNode.frame
textSelectionNode.highlightAreaNode.frame = self.textNode.frame
}
deinit {
@@ -589,6 +608,12 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, UIScroll
textFrame = CGRect(origin: CGPoint(x: sideInset, y: topInset + textOffset), size: textSize)
if self.textNode.frame != textFrame {
self.textNode.frame = textFrame
if let textSelectionNode = self.textSelectionNode {
textSelectionNode.frame = textFrame
textSelectionNode.highlightAreaNode.frame = textFrame
textSelectionNode.updateLayout()
}
}
}