diff --git a/patches/react-native+0.63.4.patch b/patches/react-native+0.63.4.patch index 0b1d76257..f2259b172 100644 --- a/patches/react-native+0.63.4.patch +++ b/patches/react-native+0.63.4.patch @@ -1,144 +1,150 @@ diff --git a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js index b124944..ca0884a 100644 --- a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js +++ b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js @@ -207,6 +207,13 @@ export type TextContentType = type PasswordRules = string; type IOSProps = $ReadOnly<{| + /** + * If `true`, allows pasting of images. + * The default value is false. + * @platform ios + */ + allowImagePaste?: ?boolean, + /** * If `false`, disables spell-check style (i.e. red underlines). * The default value is inherited from `autoCorrect`. diff --git a/node_modules/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js b/node_modules/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js index 5dc03df..e526092 100644 --- a/node_modules/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js +++ b/node_modules/react-native/Libraries/Components/Touchable/TouchableNativeFeedback.js @@ -338,7 +338,7 @@ class TouchableNativeFeedback extends React.Component { } const getBackgroundProp = - Platform.OS === 'android' + Platform.OS === 'android' && Platform.Version >= 21 ? (background, useForeground) => useForeground && TouchableNativeFeedback.canUseNativeForeground() ? {nativeForegroundAndroid: background} diff --git a/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h b/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h index 7e12add..f6c9e40 100644 --- a/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h +++ b/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h @@ -36,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN // The `caretHidden` property actually is not supported yet; // it's declared here only to conform to the interface. @property (nonatomic, assign) BOOL caretHidden; +@property (nonatomic, assign) BOOL allowImagePaste; @end diff --git a/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m b/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m index 88d3183..79185de 100644 --- a/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m +++ b/node_modules/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.m @@ -173,6 +173,9 @@ - (void)setSelectedTextRange:(UITextRange *)selectedTextRange notifyDelegate:(BO - (void)paste:(id)sender { + if ([UIPasteboard generalPasteboard].hasImages && _allowImagePaste) { + [_textInputDelegate textInputImagePasted]; + } [super paste:sender]; _textWasPasted = YES; } @@ -261,6 +264,9 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender return NO; } + if (action == @selector(paste:) && [UIPasteboard generalPasteboard].hasImages) { + return _allowImagePaste; + } return [super canPerformAction:action withSender:sender]; } diff --git a/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h b/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h index 3e1839b..2df81fb 100644 --- a/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +++ b/node_modules/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h @@ -32,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)textInputDidChange; - (void)textInputDidChangeSelection; +- (void)textInputImagePasted; @optional diff --git a/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m b/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m -index aa69593..007c6b0 100644 +index aa69593..d00bc93 100644 --- a/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -19,6 +19,8 @@ #import #import +#import + @implementation RCTBaseTextInputView { __weak RCTBridge *_bridge; __weak RCTEventDispatcher *_eventDispatcher; -@@ -479,6 +481,39 @@ - (void)textInputDidChangeSelection +@@ -479,6 +481,45 @@ - (void)textInputDidChangeSelection }); } +- (void)textInputImagePasted +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; + NSData *imageData = [clipboard dataForPasteboardType:(NSString*)kUTTypeImage]; ++ + UIImage *uiImage = [UIImage imageWithData:imageData]; + + if (!imageData) { + RCTLog(@"Failed to get image from UIPasteboard."); + return; + } + + NSString *fileName = [@([imageData hash]) stringValue]; -+ NSString *fileDest = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; ++ NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES]; ++ ++ // We add the PNG file extension because EXImageLoader fails without it. ++ // Our code ignores file extensions and looks at magic numbers directly. ++ NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:fileName] URLByAppendingPathExtension:@"png"]; ++ NSString *fileDest = [fileURL path]; + + if (![fileManager fileExistsAtPath:fileDest]) { + BOOL fileWritten = [imageData writeToFile:fileDest atomically:true]; + if (!fileWritten) { + RCTLog(@"Failed to save image to temporary directory."); + return; + } + } + + NSDictionary *eventBody = @{ + @"fileName": fileName, + @"filePath": fileDest, + @"height": @(uiImage.size.height), + @"width": @(uiImage.size.width), + }; + + [_eventDispatcher sendAppEventWithName:@"imagePasted" body:eventBody]; +} + - (void)updateLocalData { [self enforceTextAttributesIfNeeded]; diff --git a/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m b/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m index dca1437..5af6457 100644 --- a/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +++ b/node_modules/react-native/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m @@ -33,6 +33,7 @@ @implementation RCTBaseTextInputViewManager #pragma mark - Unified properties +RCT_REMAP_VIEW_PROPERTY(allowImagePaste, backedTextInputView.allowImagePaste, BOOL) RCT_REMAP_VIEW_PROPERTY(autoCapitalize, backedTextInputView.autocapitalizationType, UITextAutocapitalizationType) RCT_REMAP_VIEW_PROPERTY(autoCorrect, backedTextInputView.autocorrectionType, UITextAutocorrectionType) RCT_REMAP_VIEW_PROPERTY(contextMenuHidden, backedTextInputView.contextMenuHidden, BOOL)