mattermost-mobile/ios/Mattermost/Mattermost+RCTUITextView.m
Ewe Tek Min 0d1fd78263 MM-9599 Paste image from clipboard (#3084)
* Show image paste menu

* Get pasted image

* Add more info for file

* Add custom text input and add extension

* Dismiss contextual menu after paste image

* Group image info together

* Add max file check

* Fix max file size text

* Add PropTypes

* Add support for gif and tiff

* add onchange null check

* Use onPaste event

* Move get image info logic

* Clean up listener when no observer

* Add android upload

* Copy file from google docs

* Clean up file after upload

* Prevent text pasted in textbox if it's content uri

* Rename paste file thread

* Move on paste listener logic

* Remove the redundant data in ios

* Get realpath of item

* Clean up

* Only download for image

* Rename to custom text input

* Update RNPasteableEditTextOnPasteListener.java

* Handle for download image failed

* Fix eslint

* Fix test

* Allow multiple images to be pasted

* Remove additional null check

* Add managed control for Android

* Disable only copy, cut and paste

* Accept image in Android edit text

* Add comment for custom text input

* Do not upload when more than max file

* Stop uplaod when exceed file size

* Fix crash when clip data is null

* Return error to JS

* Move download file logic

* Remove console

* Add some tests

* Add test for handleUploadImages

* Add test for file_upload_item

* Use ImageCacheManager to cache remote images

* Fix crashes from one note

* Remove commented code

* Update test
2019-09-16 20:10:14 -03:00

59 lines
1.5 KiB
Objective-C

//
// Mattermost+RCTUITextView.m
// Mattermost
//
// Created by Elias Nahum on 6/18/19.
// Copyright © 2019 Facebook. All rights reserved.
//
#import "Mattermost+RCTUITextView.h"
#import "RCTUITextView.h"
#import <React/RCTUtils.h>
#import "RCTMultilineTextInputView.h"
#import "OnPasteEventManager.h"
#import "UIPasteboard+GetImageInfo.h"
@implementation Mattermost_RCTUITextView
@end
@implementation RCTUITextView (DisableCopyPaste)
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
NSDictionary *response = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"com.apple.configuration.managed"];
if(response) {
NSString *copyPasteProtection = response[@"copyAndPasteProtection"];
BOOL prevent = action == @selector(paste:) ||
action == @selector(copy:) ||
action == @selector(cut:) ||
action == @selector(_share:);
if ([copyPasteProtection isEqual: @"true"] && prevent) {
return NO;
}
}
// Allow copy and paste string and image
if (action == @selector(paste:)) {
return [UIPasteboard generalPasteboard].string != nil || [UIPasteboard generalPasteboard].image != nil;
}
return [super canPerformAction:action withSender:sender];
}
-(void)paste:(id)sender {
[super paste:sender];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
if (!pasteboard.hasImages) {
return;
}
NSArray<NSDictionary *> *images = [pasteboard getCopiedImages];
[OnPasteEventManager pasteImage:images];
// Dismiss contextual menu
[self resignFirstResponder];
}
@end