In React Native, with the Clipboard, how can I place an image in the Clipboard? The only method provided to set Clipboard content is "setString". Can you not set images or other content than strings?
Set selectable prop of the Text component true and the content will be copied to the clipboard with long press on the text.
You can paste using the keybind Ctrl + V while focus is on the grid.
Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.
It is possible to bridge native iOS clipboard API and expose the setImage
method. To do that you need:
Clipboard.h
:#import "RCTBridgeModule.h"
@interface Clipboard : NSObject <RCTBridgeModule>
@end
Clipboard.m
. We needed to copy base64 encoded images but you can adjust the code use any other image representation:#import <UIKit/UIKit.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import "Clipboard.h"
@implementation Clipboard
RCT_EXPORT_MODULE(BetterClipboard); // this is how our native module will be named
RCT_EXPORT_METHOD(addBase64Image:(NSString *)base64Image) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setPersistent:YES];
NSData *imageData = [[NSData alloc]initWithBase64EncodedString:base64Image options:NSDataBase64DecodingIgnoreUnknownCharacters];
[pasteboard setImage:[UIImage imageWithData:imageData]];
}
@end
import { NativeModules } from 'react-native';
NativeModules.BetterClipboard.addBase64Image(base64EncodedImage);
Unfortunately, I don't know how to do the same for Android.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With