-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add onPaste to TextInput #45425
Draft
s77rt
wants to merge
20
commits into
facebook:main
Choose a base branch
from
s77rt:TextInput-onPaste
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add onPaste to TextInput #45425
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
99c46e8
Add onPaste to TextInput
s77rt 61cc3c7
Update snapshot
s77rt 9b4aaf5
return valid getEventData
s77rt 8f504d1
Call onPaste before pasting the text
s77rt 27743c6
Better onPaste comment
s77rt af06d9e
Android: Pass clipboard data to onPaste event
s77rt d0b72ed
RN-Tester: PasteboardTextInput fix image size
s77rt 4a6bed5
rename variable
s77rt 5baad1a
Update Podfile.lock
s77rt b04cca8
iOS: Pass clipboard data to onPaste event
s77rt c580a3b
Revert "Update Podfile.lock"
s77rt 661b0aa
Merge branch 'facebook:main' into TextInput-onPaste
s77rt 5e82920
iOS: Support image pasting
s77rt 2fe029c
Update onPaste prop
s77rt 401d597
fix flow check
s77rt df52d5c
format
s77rt 8bf252a
Pass URI instead of base64 encoded data for files
s77rt 6a2f11b
use identifier that conforms to UTTypeImage
s77rt 01e7521
iOS: Use unique filename on paste
s77rt 0919a38
Merge branch 'facebook:main' into TextInput-onPaste
s77rt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
#import <React/RCTUtils.h> | ||
#import <React/UIView+React.h> | ||
|
||
#import <MobileCoreServices/MobileCoreServices.h> | ||
#import <MobileCoreServices/UTType.h> | ||
#import <UIKit/UIKit.h> | ||
|
||
@implementation RCTUITextField { | ||
RCTBackedTextFieldDelegateAdapter *_textInputDelegateAdapter; | ||
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes; | ||
|
@@ -139,6 +143,10 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender | |
return NO; | ||
} | ||
|
||
if (action == @selector(paste:) && [UIPasteboard generalPasteboard].hasImages) { | ||
return YES; | ||
} | ||
|
||
return [super canPerformAction:action withSender:sender]; | ||
} | ||
|
||
|
@@ -222,7 +230,32 @@ - (void)scrollRangeToVisible:(NSRange)range | |
- (void)paste:(id)sender | ||
{ | ||
_textWasPasted = YES; | ||
[super paste:sender]; | ||
UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; | ||
if (clipboard.hasImages) { | ||
for (NSItemProvider *itemProvider in clipboard.itemProviders) { | ||
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) { | ||
for (NSString *identifier in itemProvider.registeredTypeIdentifiers) { | ||
if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeImage)) { | ||
NSString *MIMEType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)identifier, kUTTagClassMIMEType); | ||
NSString *fileExtension = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)identifier, kUTTagClassFilenameExtension); | ||
NSString *fileName = [NSString stringWithFormat:@"%@.%@", [[NSUUID UUID] UUIDString], fileExtension]; | ||
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; | ||
Comment on lines
+241
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same ^ |
||
NSURL *fileURL = [NSURL fileURLWithPath:filePath]; | ||
NSData *fileData = [clipboard dataForPasteboardType:identifier]; | ||
[fileData writeToFile:filePath atomically:YES]; | ||
[_textInputDelegateAdapter didPaste:MIMEType withData:[fileURL absoluteString]]; | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} else { | ||
if (clipboard.hasStrings) { | ||
[_textInputDelegateAdapter didPaste:@"text/plain" withData:clipboard.string]; | ||
} | ||
[super paste:sender]; | ||
} | ||
} | ||
|
||
#pragma mark - Layout | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with
RCTTempFilePath