* 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
52 lines
1.7 KiB
Objective-C
52 lines
1.7 KiB
Objective-C
//
|
|
// UIPasteboard+GetImageInfo.m
|
|
// Mattermost
|
|
//
|
|
// Created by Tek Min Ewe on 05/08/2019.
|
|
// Copyright © 2019 Facebook. All rights reserved.
|
|
//
|
|
|
|
#import "UIPasteboard+GetImageInfo.h"
|
|
#import "NSData+MimeType.h"
|
|
|
|
@implementation UIPasteboard (GetImageInfo)
|
|
|
|
-(NSArray<NSDictionary *> *)getCopiedImages {
|
|
NSArray<UIImage *> *images = self.images;
|
|
NSMutableArray<NSDictionary *> *imageInfos = [[NSMutableArray alloc] init];
|
|
for (int i = 0; i < images.count; i++) {
|
|
UIImage *image = images[i];
|
|
NSString *uri = self.string;
|
|
NSArray<NSString *> *types = self.pasteboardTypes;
|
|
|
|
NSData *imageData;
|
|
if ([types[0] isEqual:@"public.jpeg"]) {
|
|
imageData = UIImageJPEGRepresentation(image, 1.0);
|
|
} else if ([types[0] isEqual:@"public.png"]) {
|
|
imageData = UIImagePNGRepresentation(image);
|
|
} else {
|
|
imageData = [self dataForPasteboardType:types[0]];
|
|
}
|
|
NSString *extension = [imageData extension];
|
|
NSString *mimeType = [imageData mimeType];
|
|
|
|
NSString *tempFilename = [NSString stringWithFormat:@"%@%@", [[NSProcessInfo processInfo] globallyUniqueString], extension];
|
|
NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:tempFilename]];
|
|
BOOL success = [imageData writeToURL:tempFileURL atomically:YES];
|
|
|
|
if (success) {
|
|
uri = tempFileURL.absoluteString;
|
|
}
|
|
|
|
[imageInfos addObject:@{
|
|
@"fileName": tempFilename,
|
|
@"fileSize": @([imageData length]),
|
|
@"type": mimeType,
|
|
@"uri": uri,
|
|
}];
|
|
}
|
|
|
|
return imageInfos;
|
|
}
|
|
|
|
@end
|