Browse Source

fix: 修复复制文字的Clipboard api

zengkunsen 4 months ago
parent
commit
c6c6d0923c
3 changed files with 85 additions and 98 deletions
  1. 11 24
      package-lock.json
  2. 72 72
      package.json
  3. 2 2
      util/index.ts

+ 11 - 24
package-lock.json

@@ -11,7 +11,6 @@
       "dependencies": {
         "@gorhom/bottom-sheet": "^5.1.8",
         "@react-native-async-storage/async-storage": "2.2.0",
-        "@react-native-clipboard/clipboard": "^1.16.3",
         "@shopify/flash-list": "2.0.2",
         "@tanstack/react-query": "^5.85.0",
         "@types/lodash": "^4.17.20",
@@ -24,6 +23,7 @@
         "expo": "^53.0.0",
         "expo-camera": "~16.1.11",
         "expo-checkbox": "~4.1.4",
+        "expo-clipboard": "~7.1.5",
         "expo-constants": "~17.1.7",
         "expo-dev-client": "~5.2.4",
         "expo-device": "~7.1.4",
@@ -2587,29 +2587,6 @@
         "react-native": "^0.0.0-0 || >=0.65 <1.0"
       }
     },
-    "node_modules/@react-native-clipboard/clipboard": {
-      "version": "1.16.3",
-      "resolved": "https://registry.npmmirror.com/@react-native-clipboard/clipboard/-/clipboard-1.16.3.tgz",
-      "integrity": "sha512-cMIcvoZKIrShzJHEaHbTAp458R9WOv0fB6UyC7Ek4Qk561Ow/DrzmmJmH/rAZg21Z6ixJ4YSdFDC14crqIBmCQ==",
-      "license": "MIT",
-      "workspaces": [
-        "example"
-      ],
-      "peerDependencies": {
-        "react": ">= 16.9.0",
-        "react-native": ">= 0.61.5",
-        "react-native-macos": ">= 0.61.0",
-        "react-native-windows": ">= 0.61.0"
-      },
-      "peerDependenciesMeta": {
-        "react-native-macos": {
-          "optional": true
-        },
-        "react-native-windows": {
-          "optional": true
-        }
-      }
-    },
     "node_modules/@react-native/assets-registry": {
       "version": "0.79.5",
       "resolved": "https://registry.npmmirror.com/@react-native/assets-registry/-/assets-registry-0.79.5.tgz",
@@ -4933,6 +4910,16 @@
         }
       }
     },
+    "node_modules/expo-clipboard": {
+      "version": "7.1.5",
+      "resolved": "https://registry.npmmirror.com/expo-clipboard/-/expo-clipboard-7.1.5.tgz",
+      "integrity": "sha512-TCANUGOxouoJXxKBW5ASJl2WlmQLGpuZGemDCL2fO5ZMl57DGTypUmagb0CVUFxDl0yAtFIcESd78UsF9o64aw==",
+      "peerDependencies": {
+        "expo": "*",
+        "react": "*",
+        "react-native": "*"
+      }
+    },
     "node_modules/expo-constants": {
       "version": "17.1.7",
       "resolved": "https://registry.npmmirror.com/expo-constants/-/expo-constants-17.1.7.tgz",

+ 72 - 72
package.json

@@ -1,74 +1,74 @@
 {
-    "name": "template",
-    "version": "1.0.0",
-    "main": "expo-router/entry",
-    "scripts": {
-        "start": "expo start --dev-client",
-        "android": "expo run:android",
-        "ios": "expo run:ios",
-        "web": "expo start --web",
-        "postinstall": "patch-package"
-    },
-    "dependencies": {
-        "@gorhom/bottom-sheet": "^5.1.8",
-        "@react-native-async-storage/async-storage": "2.2.0",
-        "@react-native-clipboard/clipboard": "^1.16.3",
-        "@shopify/flash-list": "2.0.2",
-        "@tanstack/react-query": "^5.85.0",
-        "@types/lodash": "^4.17.20",
-        "@types/react-native-datepicker": "^1.7.6",
-        "axios": "^1.11.0",
-        "crypto-js": "^4.2.0",
-        "date-fns": "4.1.0",
-        "date-fns-tz": "^3.2.0",
-        "dotenv": "^17.2.1",
-        "expo": "^53.0.0",
-        "expo-camera": "~16.1.11",
-        "expo-checkbox": "~4.1.4",
-        "expo-constants": "~17.1.7",
-        "expo-dev-client": "~5.2.4",
-        "expo-device": "~7.1.4",
-        "expo-env": "^1.1.1",
-        "expo-file-system": "~18.1.11",
-        "expo-image-picker": "~16.1.4",
-        "expo-linking": "~7.1.7",
-        "expo-location": "~18.1.6",
-        "expo-notifications": "~0.31.4",
-        "expo-router": "~5.1.4",
-        "expo-secure-store": "~14.2.3",
-        "expo-status-bar": "~2.2.3",
-        "expo-updates": "~0.28.17",
-        "lodash": "^4.17.21",
-        "nativewind": "^4.1.23",
-        "prettier-plugin-tailwindcss": "^0.6.14",
-        "react": "19.0.0",
-        "react-native": "0.79.5",
-        "react-native-element-dropdown": "^2.12.4",
-        "react-native-gesture-handler": "~2.28.0",
-        "react-native-keyboard-aware-scroll-view": "^0.9.5",
-        "react-native-maps": "1.20.1",
-        "react-native-modal": "14.0.0-rc.1",
-        "react-native-modern-datepicker": "^1.0.0-beta.91",
-        "react-native-pager-view": "^6.9.1",
-        "react-native-reanimated": "~3.17.4",
-        "react-native-responsive-screen": "^1.4.2",
-        "react-native-safe-area-context": "5.6.0",
-        "react-native-screens": "~4.13.1",
-        "react-native-svg": "15.12.1",
-        "react-native-tab-view": "4.1.3",
-        "react-native-webview": "13.15.0",
-        "zustand": "^4.5.2"
-    },
-    "devDependencies": {
-        "@babel/core": "^7.28.0",
-        "@types/crypto-js": "^4.2.2",
-        "@types/react": "~19.0.10",
-        "@types/react-native-modern-datepicker": "^1.0.5",
-        "lightningcss": "^1.30.1",
-        "patch-package": "^8.0.0",
-        "postinstall-postinstall": "^2.1.0",
-        "tailwindcss": "^3.4.17",
-        "typescript": "~5.9.2"
-    },
-    "private": true
+  "name": "template",
+  "version": "1.0.0",
+  "main": "expo-router/entry",
+  "scripts": {
+    "start": "expo start --dev-client",
+    "android": "expo run:android",
+    "ios": "expo run:ios",
+    "web": "expo start --web",
+    "postinstall": "patch-package"
+  },
+  "dependencies": {
+    "@gorhom/bottom-sheet": "^5.1.8",
+    "@react-native-async-storage/async-storage": "2.2.0",
+    "@shopify/flash-list": "2.0.2",
+    "@tanstack/react-query": "^5.85.0",
+    "@types/lodash": "^4.17.20",
+    "@types/react-native-datepicker": "^1.7.6",
+    "axios": "^1.11.0",
+    "crypto-js": "^4.2.0",
+    "date-fns": "4.1.0",
+    "date-fns-tz": "^3.2.0",
+    "dotenv": "^17.2.1",
+    "expo": "^53.0.0",
+    "expo-camera": "~16.1.11",
+    "expo-checkbox": "~4.1.4",
+    "expo-constants": "~17.1.7",
+    "expo-dev-client": "~5.2.4",
+    "expo-device": "~7.1.4",
+    "expo-env": "^1.1.1",
+    "expo-file-system": "~18.1.11",
+    "expo-image-picker": "~16.1.4",
+    "expo-linking": "~7.1.7",
+    "expo-location": "~18.1.6",
+    "expo-notifications": "~0.31.4",
+    "expo-router": "~5.1.4",
+    "expo-secure-store": "~14.2.3",
+    "expo-status-bar": "~2.2.3",
+    "expo-updates": "~0.28.17",
+    "lodash": "^4.17.21",
+    "nativewind": "^4.1.23",
+    "prettier-plugin-tailwindcss": "^0.6.14",
+    "react": "19.0.0",
+    "react-native": "0.79.5",
+    "react-native-element-dropdown": "^2.12.4",
+    "react-native-gesture-handler": "~2.28.0",
+    "react-native-keyboard-aware-scroll-view": "^0.9.5",
+    "react-native-maps": "1.20.1",
+    "react-native-modal": "14.0.0-rc.1",
+    "react-native-modern-datepicker": "^1.0.0-beta.91",
+    "react-native-pager-view": "^6.9.1",
+    "react-native-reanimated": "~3.17.4",
+    "react-native-responsive-screen": "^1.4.2",
+    "react-native-safe-area-context": "5.6.0",
+    "react-native-screens": "~4.13.1",
+    "react-native-svg": "15.12.1",
+    "react-native-tab-view": "4.1.3",
+    "react-native-webview": "13.15.0",
+    "zustand": "^4.5.2",
+    "expo-clipboard": "~7.1.5"
+  },
+  "devDependencies": {
+    "@babel/core": "^7.28.0",
+    "@types/crypto-js": "^4.2.2",
+    "@types/react": "~19.0.10",
+    "@types/react-native-modern-datepicker": "^1.0.5",
+    "lightningcss": "^1.30.1",
+    "patch-package": "^8.0.0",
+    "postinstall-postinstall": "^2.1.0",
+    "tailwindcss": "^3.4.17",
+    "typescript": "~5.9.2"
+  },
+  "private": true
 }

+ 2 - 2
util/index.ts

@@ -1,5 +1,5 @@
 import { Linking, Alert } from 'react-native';
-import Clipboard from '@react-native-clipboard/clipboard';
+import * as Clipboard from 'expo-clipboard';
 export const handleGoWhatsApp = async () => {
   const phoneWithCountryCode = '85291382139'; // 不带 "+",如 +60 改成 60(马来西亚)
   const message = '';
@@ -20,7 +20,7 @@ export const handleGoWhatsApp = async () => {
     console.error('Error opening WhatsApp:', error);
     // Fallback to showing the number if both methods fail
     Alert.alert('聯絡我們', `請通過WhatsApp聯繫我們:${phoneWithCountryCode}`, [
-      { text: '複製號碼', onPress: () => Clipboard.setString(phoneWithCountryCode) },
+      { text: '複製號碼', onPress: async () => await Clipboard.setStringAsync(phoneWithCountryCode) },
       { text: '取消', style: 'cancel' }
     ]);
   }