This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 剪贴板 iconExpo 剪贴板

一个通用库,允许获取和设置剪贴板内容。

Android
iOS
Web
Included in Expo Go
Recommended version:
~58.0.3

expo-clipboard 提供了一个接口,用于在 Android、iOS 和网页上获取和设置剪贴板内容。

安装

🌐 Installation

Terminal
- npx expo install expo-clipboard
- yarn expo install expo-clipboard
- pnpm expo install expo-clipboard
- bun expo install expo-clipboard

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

Clipboard
import { useState } from 'react'; import { View, Text, Button, StyleSheet } from 'react-native'; import * as Clipboard from 'expo-clipboard'; export default function App() { const [copiedText, setCopiedText] = useState(''); const copyToClipboard = async () => { await Clipboard.setStringAsync('hello world'); }; const fetchCopiedText = async () => { const text = await Clipboard.getStringAsync(); setCopiedText(text); }; return ( <View style={styles.container}> <Button title="点击此处复制到剪贴板" onPress={copyToClipboard} /> <Button title="查看已复制的文本" onPress={fetchCopiedText} /> <Text style={styles.copiedText}>{copiedText}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, copiedText: { marginTop: 10, color: 'red', }, });

将剪贴板内容标记为敏感(安卓)

🌐 Mark clipboard content as sensitive (Android)

当你复制敏感数据,比如密码、一次性密码(OTP)、访问令牌、支付信息或个人身份信息(PII)时,请在 setStringAsync 和 setImageAsync 中设置 android.isSensitive。

🌐 When you copy sensitive data such as passwords, one-time passwords (OTPs), access tokens, payment details, or personally identifiable information (PII), set android.isSensitive in setStringAsync and setImageAsync.

设置 android.isSensitive: true 会将剪贴板内容标记为敏感,基于 Android 关于安全剪贴板处理的指导。这可以帮助:

🌐 Setting android.isSensitive: true marks clipboard content as sensitive, based on Android guidance for secure clipboard handling. This can help:

  • 混淆键盘显示的剪贴板预览
  • 在安卓13及更高版本隐藏剪贴板预览覆盖
  • 减少被肩窥意外暴露
import * as Clipboard from 'expo-clipboard'; // Sensitive text await Clipboard.setStringAsync('my-secret-token', { android: { isSensitive: true }, }); // Sensitive image await Clipboard.setImageAsync(base64Image, { android: { isSensitive: true }, });

应用接口

🌐 API

import * as Clipboard from 'expo-clipboard';

No API data file found, sorry!