From a82c2e9a7821c761eb1f964131a0e96bfa41c1aa Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 29 Oct 2026 18:29:32 -0400 Subject: [PATCH 1/2] Share.share copies message and url as a single pasteboard item on iOS --- .../CoreModules/RCTActionSheetManager.mm | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index d615eca6e8a3..e9722a85ecfe 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -22,6 +22,55 @@ using namespace facebook::react; +@interface RCTShareActivityItemSource : NSObject + +- (instancetype)initWithItem:(id)item pasteboardItem:(nullable id)pasteboardItem subject:(nullable NSString *)subject; + +@end + +@implementation RCTShareActivityItemSource { + id _item; + id _pasteboardItem; + NSString *_subject; +} + +- (instancetype)initWithItem:(id)item pasteboardItem:(nullable id)pasteboardItem subject:(nullable NSString *)subject +{ + if (self = [super init]) { + _item = item; + _pasteboardItem = pasteboardItem; + _subject = subject; + } + return self; +} + +- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController +{ + return _item; +} + +- (nullable id)activityViewController:(UIActivityViewController *)activityViewController + itemForActivityType:(nullable UIActivityType)activityType +{ + return [activityType isEqualToString:UIActivityTypeCopyToPasteboard] ? _pasteboardItem : _item; +} + +- (BOOL)respondsToSelector:(SEL)selector +{ + if (selector == @selector(activityViewController:subjectForActivityType:)) { + return _subject != nil; + } + return [super respondsToSelector:selector]; +} + +- (NSString *)activityViewController:(UIActivityViewController *)activityViewController + subjectForActivityType:(nullable UIActivityType)activityType +{ + return _subject; +} + +@end + @interface RCTActionSheetManager () @property (nonatomic, strong) NSMutableArray *alertControllers; @@ -264,6 +313,14 @@ - (void)showShareActionSheetWithOptions: return; } [items addObject:data]; + } else if (message != nullptr) { + // On Copy, UIKit writes each activity item to its own pasteboard item, and a plain-text + // paste (including through Universal Clipboard) only reads the first one. + items[0] = [[RCTShareActivityItemSource alloc] initWithItem:message pasteboardItem:nil subject:subject]; + NSString *pasteboardText = [NSString stringWithFormat:@"%@ %@", message, URL.absoluteString]; + [items addObject:[[RCTShareActivityItemSource alloc] initWithItem:URL + pasteboardItem:pasteboardText + subject:subject]]; } else { [items addObject:URL]; } From 8392e979cf2e69f1296dd38aeb1e40912a9c7fbf Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 29 Oct 2026 18:57:19 -0400 Subject: [PATCH 2/2] Keep file URLs out of the combined Copy string and return it from the message item --- .../React/CoreModules/RCTActionSheetManager.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index e9722a85ecfe..f95b684ec560 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -313,14 +313,14 @@ - (void)showShareActionSheetWithOptions: return; } [items addObject:data]; - } else if (message != nullptr) { + } else if (message != nullptr && !URL.fileURL) { // On Copy, UIKit writes each activity item to its own pasteboard item, and a plain-text // paste (including through Universal Clipboard) only reads the first one. - items[0] = [[RCTShareActivityItemSource alloc] initWithItem:message pasteboardItem:nil subject:subject]; NSString *pasteboardText = [NSString stringWithFormat:@"%@ %@", message, URL.absoluteString]; - [items addObject:[[RCTShareActivityItemSource alloc] initWithItem:URL - pasteboardItem:pasteboardText - subject:subject]]; + items[0] = [[RCTShareActivityItemSource alloc] initWithItem:message + pasteboardItem:pasteboardText + subject:subject]; + [items addObject:[[RCTShareActivityItemSource alloc] initWithItem:URL pasteboardItem:nil subject:subject]]; } else { [items addObject:URL]; }