Cross-platform clipboard management for React Native and Expo applications with text, image, and URL support
npx @tessl/cli install tessl/npm-expo-clipboard@8.0.0Expo Clipboard provides a comprehensive cross-platform clipboard management library for React Native and Expo applications. It enables developers to interact with the system clipboard across Android, iOS, and Web platforms, supporting text, images, URLs, and clipboard change events.
npx expo install expo-clipboardimport * as Clipboard from "expo-clipboard";For specific functions:
import {
getStringAsync,
setStringAsync,
getImageAsync,
setImageAsync,
ClipboardPasteButton
} from "expo-clipboard";import * as Clipboard from "expo-clipboard";
// Basic text operations
await Clipboard.setStringAsync("Hello, world!");
const text = await Clipboard.getStringAsync();
// Check if clipboard has content
const hasText = await Clipboard.hasStringAsync();
const hasImage = await Clipboard.hasImageAsync();
// Image operations
const image = await Clipboard.getImageAsync({ format: 'png' });
if (image) {
await Clipboard.setImageAsync(image.data.split(',')[1]); // Remove data URL prefix
}Expo Clipboard is built around several key components:
getStringAsync, setStringAsync, etc.)ExpoClipboard.ts) and Web (ExpoClipboard.web.ts)ClipboardPasteButton for iOS 16+ providing permission-free paste functionalityCore clipboard text functionality supporting plain text and HTML formats with async operations and permission handling.
function getStringAsync(options?: GetStringOptions): Promise<string>;
function setStringAsync(text: string, options?: SetStringOptions): Promise<boolean>;
function hasStringAsync(): Promise<boolean>;
interface GetStringOptions {
preferredFormat?: StringFormat;
}
interface SetStringOptions {
inputFormat?: StringFormat;
}
enum StringFormat {
PLAIN_TEXT = 'plainText',
HTML = 'html'
}Clipboard image handling with Base64 encoding, format conversion, and quality controls for PNG and JPEG formats.
function getImageAsync(options: GetImageOptions): Promise<ClipboardImage | null>;
function setImageAsync(base64Image: string): Promise<void>;
function hasImageAsync(): Promise<boolean>;
interface GetImageOptions {
format: 'png' | 'jpeg';
jpegQuality?: number;
}
interface ClipboardImage {
data: string;
size: {
width: number;
height: number;
};
}Specialized URL clipboard handling that preserves URL content type information for better app integration.
function getUrlAsync(): Promise<string | null>;
function setUrlAsync(url: string): Promise<void>;
function hasUrlAsync(): Promise<boolean>;Clipboard change event listeners for detecting and responding to clipboard content changes.
function addClipboardListener(listener: (event: ClipboardEvent) => void): EventSubscription;
function removeClipboardListener(subscription: EventSubscription): void;
interface ClipboardEvent {
content: string; // @deprecated
contentTypes: ContentType[];
}
enum ContentType {
PLAIN_TEXT = 'plain-text',
HTML = 'html',
IMAGE = 'image',
URL = 'url' // iOS only
}Native iOS paste button component providing permission-free clipboard access with customizable appearance.
const isPasteButtonAvailable: boolean;
interface ClipboardPasteButtonProps {
onPress: (data: PasteEventPayload) => void;
backgroundColor?: string | null;
foregroundColor?: string | null;
cornerStyle?: CornerStyleType | null;
displayMode?: DisplayModeType | null;
imageOptions?: GetImageOptions | null;
acceptedContentTypes?: AcceptedContentType[];
style?: StyleProp<Omit<ViewStyle, 'backgroundColor' | 'borderRadius' | 'color'>>;
}
type PasteEventPayload = TextPasteEvent | ImagePasteEvent;type EventSubscription = {
remove(): void;
};
type AcceptedContentType = 'plain-text' | 'image' | 'url' | 'html';
type CornerStyleType = 'dynamic' | 'fixed' | 'capsule' | 'large' | 'medium' | 'small';
type DisplayModeType = 'iconAndLabel' | 'iconOnly' | 'labelOnly';
interface TextPasteEvent {
text: string;
type: 'text';
}
interface ImagePasteEvent extends ClipboardImage {
type: 'image';
}