copy / paste images directly
This commit is contained in:
parent
d754311395
commit
bbccbe42c1
|
@ -49,6 +49,16 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|||
}
|
||||
|
||||
// MARK: Attachments
|
||||
func didPasteImageFromPasteboard(_ image: UIImage) {
|
||||
guard let imageData = image.jpegData(compressionQuality: 1.0) else { return }
|
||||
let dataSource = DataSourceValue.dataSource(with: imageData, utiType: kUTTypeJPEG as String)
|
||||
let attachment = SignalAttachment.attachment(dataSource: dataSource, dataUTI: kUTTypeJPEG as String, imageQuality: .medium)
|
||||
|
||||
let sendMediaNavController = SendMediaNavigationController.showingWithImage(attachment, delegate: self)
|
||||
sendMediaNavController.modalPresentationStyle = .fullScreen
|
||||
self.present(sendMediaNavController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func sendMediaNavDidCancel(_ sendMediaNavigationController: SendMediaNavigationController) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
|
|
@ -37,6 +37,22 @@ public final class InputTextView : UITextView, UITextViewDelegate {
|
|||
public required init?(coder: NSCoder) {
|
||||
preconditionFailure("Use init(delegate:) instead.")
|
||||
}
|
||||
|
||||
public override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||
if action == #selector(paste(_:)) {
|
||||
if let _ = UIPasteboard.general.image {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.canPerformAction(action, withSender: sender)
|
||||
}
|
||||
|
||||
public override func paste(_ sender: Any?) {
|
||||
if let image = UIPasteboard.general.image {
|
||||
snDelegate?.didPasteImageFromPasteboard(self, image: image)
|
||||
}
|
||||
super.paste(sender)
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
showsHorizontalScrollIndicator = false
|
||||
|
@ -80,4 +96,5 @@ protocol InputTextViewDelegate : AnyObject {
|
|||
|
||||
func inputTextViewDidChangeSize(_ inputTextView: InputTextView)
|
||||
func inputTextViewDidChangeContent(_ inputTextView: InputTextView)
|
||||
func didPasteImageFromPasteboard(_ inputTextView: InputTextView, image: UIImage)
|
||||
}
|
||||
|
|
|
@ -143,6 +143,10 @@ final class InputView : UIView, InputViewButtonDelegate, InputTextViewDelegate,
|
|||
autoGenerateLinkPreviewIfPossible()
|
||||
delegate?.inputTextViewDidChangeContent(inputTextView)
|
||||
}
|
||||
|
||||
func didPasteImageFromPasteboard(_ inputTextView: InputTextView, image: UIImage) {
|
||||
delegate?.didPasteImageFromPasteboard(image)
|
||||
}
|
||||
|
||||
// We want to show either a link preview or a quote draft, but never both at the same time. When trying to
|
||||
// generate a link preview, wait until we're sure that we'll be able to build a link preview from the given
|
||||
|
@ -351,4 +355,5 @@ protocol InputViewDelegate : AnyObject, ExpandingAttachmentsButtonDelegate, Voic
|
|||
func handleQuoteViewCancelButtonTapped()
|
||||
func inputTextViewDidChangeContent(_ inputTextView: InputTextView)
|
||||
func handleMentionSelected(_ mention: Mention, from view: MentionSelectionView)
|
||||
func didPasteImageFromPasteboard(_ image: UIImage)
|
||||
}
|
||||
|
|
|
@ -58,6 +58,17 @@ class SendMediaNavigationController: OWSNavigationController {
|
|||
|
||||
@objc
|
||||
public weak var sendMediaNavDelegate: SendMediaNavDelegate?
|
||||
|
||||
@objc class func showingWithImage(_ attachment: SignalAttachment, delegate: SendMediaNavDelegate) -> SendMediaNavigationController {
|
||||
let navController = SendMediaNavigationController()
|
||||
navController.sendMediaNavDelegate = delegate
|
||||
let approvalViewController = AttachmentApprovalViewController(mode: .modal, attachments: [ attachment ])
|
||||
approvalViewController.approvalDelegate = navController
|
||||
approvalViewController.messageText = delegate.sendMediaNavInitialMessageText(navController)
|
||||
navController.setViewControllers([approvalViewController], animated: false)
|
||||
|
||||
return navController
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func showingCameraFirst() -> SendMediaNavigationController {
|
||||
|
|
Loading…
Reference in New Issue