Closed kylehorn closed 8 years ago
It looks like UITextViewTextDidChangeNotification
and SLKTextViewContentSizeDidChangeNotification
are not being triggered. We don't yet support NSTextAttachment
.
There was a great PR from a while back, you might want to take a look at. https://github.com/slackhq/SlackTextViewController/pull/120/files
Is there a plan to merge that PR at some point? That seems like it would solve my issue.
Probably, but it's somewhat deprecated (lots of things changed since that PR). There hasn't been many people complaining/asking for this feature yet, so it hasn't been set as a high priority thing.
We're relying quite heavily on NSTextAttachment so i'll have to look into it more. Is it something that the media pasteboard could solve?
The media pasteboard only detects the type of object pasted into the text view, and sends a notification.
I assume you want to display an image using NSTextAttachment
in the text view, so I don't think that would help.
Try forking the project, extend it using that PR's implementation. If you get to a good and backwards compatible solution, please submit a PR for it and I'll review it.
Sounds good, I'll give it a go.
Thanks!
@kylehorn @dzenbot were there any PRs or commits made for this enhancement?
This has been addressed here: https://github.com/slackhq/SlackTextViewController/pull/501
If anyone is looking at this issue to try and figure out how to add support for pasting images into the textView, here are a couple of tips:
1) Turn on support for pasting images:
textView.pastableMediaTypes = .images
2) Override didPasteMediaContent():
override func didPasteMediaContent(_ userInfo: [AnyHashable : Any]) {
guard let pasteUTI = userInfo["SLKTextViewPastedItemContentType"] as? String,
let pasteData = userInfo["SLKTextViewPastedItemData"] as? Data else {
return
}
if let image = UIImage(data: pasteData) {
let attachment = NSTextAttachment(data: pasteData, ofType: pasteUTI)
let attrString = NSAttributedString(attachment: attachment)
textView.slk_insertAttributedText(atCaretRange: attrString)
}
}
2.5) you may need a UTI helper class like SwiftUTI to help with converting UTIs and mimeTypes 3) You may want to insert a thumbnail instead of the full size image; if you do you may want to subclass NSTextAttachment to contain the original UTI and image data 4) on send, you will need to figure out how to send the combined text+data, or pull out the attachments and send separately. There are some useful functions like slk_hasImageAttachment() in #120 to use as an example.
Adding a NSTextAttachment in code doesn't update showing the send button.
Is there any way to override if the "Send" button should show?