Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PasteInputEditText(context: ThemedReactContext) : ReactEditText(context) {
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection {
val ic = super.onCreateInputConnection(outAttrs)

EditorInfoCompat.setContentMimeTypes(outAttrs, arrayOf<String>("*/*"))
EditorInfoCompat.setContentMimeTypes(outAttrs, arrayOf("image/gif", "image/jpg", "image/jpeg", "image/png", "image/webp", "image/*", "*/*"))

val callback = InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, opts ->
val lacksPermission = (flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0
Expand Down
14 changes: 7 additions & 7 deletions ios/PasteInputTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
action == @selector(cut:) ||
action == @selector(_share:);
#pragma clang diagnostic pop

if (_disableCopyPaste && prevent) {
return NO;
}

if (action == @selector(paste:) && [UIPasteboard generalPasteboard].numberOfItems > 0) {
return true;
}

return [super canPerformAction:action withSender:sender];
}

-(void)paste:(id)sender {
[super paste:sender];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

BOOL hasStrings = pasteboard.hasStrings;
Expand All @@ -49,7 +49,7 @@ -(void)paste:(id)sender {
if (pasteboard.hasURLs || hasStrings || pasteboard.hasColors) {
return;
}

if (_onPaste) {
NSArray<NSDictionary *> *files = [pasteboard getCopiedFiles];
if (files != nil && files.count > 0) {
Expand All @@ -60,9 +60,9 @@ -(void)paste:(id)sender {
return;
}
}

// Dismiss contextual menu
[self resignFirstResponder];
// [self resignFirstResponder];
}

@end
18 changes: 9 additions & 9 deletions ios/UIPasteboard+GetImageInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "UIPasteboard+GetImageInfo.h"
#import "NSData+MimeType.h"
#import "react_native_paste_input-Swift.h"
#import "react_native_paste_input/react_native_paste_input-Swift.h"
#import "UIImage+vImageScaling.h"

@implementation UIPasteboard (GetImageInfo)
Expand All @@ -25,18 +25,18 @@ @implementation UIPasteboard (GetImageInfo)
}

NSString *type = item.allKeys[j];


@try {
NSString *uri = self.string;
NSData *fileData = item[type];

if ([type isEqual:@"public.jpeg"] || [type isEqual:@"public.heic"] || [type isEqual:@"public.png"]) {
fileData = [self getDataForImageItem:item[type] type:type];
} else if ([type isEqual:@"com.compuserve.gif"]) {
fileData = [self dataForPasteboardType:type];
}

SwimeProxy *swimeProxy = [SwimeProxy shared];
MimeTypeProxy *mimeProxy = [swimeProxy getMimeAndExtensionWithData:fileData uti:type];
NSString *extension;
Expand All @@ -48,11 +48,11 @@ @implementation UIPasteboard (GetImageInfo)
extension = [fileData extension];
mimeType = [fileData mimeType];
}

if ([extension length] == 0) {
continue;
}

NSString *tempFilename = [NSString stringWithFormat:@"%@.%@", [[NSProcessInfo processInfo] globallyUniqueString], extension];
NSURL *tempFileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:tempFilename]];
BOOL success = [fileData writeToURL:tempFileURL atomically:YES];
Expand All @@ -74,7 +74,7 @@ @implementation UIPasteboard (GetImageInfo)
}
}
}

return fileInfos;
}

Expand All @@ -93,11 +93,11 @@ -(NSData *) getDataForImageItem:(NSData *)imageData type:(NSString *)type {
if (width > 6048 || height > 4032) {
image = [image vImageScaledImageWithSize:CGSizeMake(2048, 2048) contentMode:UIViewContentModeScaleAspectFit];
}

if ([type isEqual:@"public.png"]) {
return UIImagePNGRepresentation(image);
}

return UIImageJPEGRepresentation(image, 1.0);
}

Expand Down