@multiplatform.one/platform 7.7.6 → 7.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/platform",
3
- "version": "7.7.6",
3
+ "version": "7.8.0",
4
4
  "description": "Platform detection flags and utilities for multiplatform.one",
5
5
  "keywords": [
6
6
  "detection",
@@ -55,7 +55,7 @@
55
55
  "react": "19.2.5",
56
56
  "typescript": "~5.9.3",
57
57
  "vitest": "^4.1.5",
58
- "@multiplatform.one/config": "7.7.6"
58
+ "@multiplatform.one/config": "7.8.0"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "expo-constants": "~55.0.15",
@@ -1,3 +1,12 @@
1
- export async function writeToClipboard(_text: string): Promise<boolean> {
2
- return false;
1
+ import { Clipboard } from "react-native";
2
+
3
+ export async function writeToClipboard(text: string): Promise<boolean> {
4
+ try {
5
+ // Core Clipboard is present in the pinned native runtime. Access stays
6
+ // inside the guard so an unavailable module reports failure when copying.
7
+ Clipboard.setString(text);
8
+ return true;
9
+ } catch {
10
+ return false;
11
+ }
3
12
  }
@@ -1,5 +1,15 @@
1
1
  import { describe, expect, it, vi, beforeEach } from "vitest";
2
2
  import { writeToClipboard } from "./clipboard";
3
+ import { writeToClipboard as writeNativeClipboard } from "./clipboard.native";
4
+
5
+ const native = vi.hoisted(() => ({
6
+ clipboard: undefined as { setString: (text: string) => void } | undefined,
7
+ }));
8
+ vi.mock("react-native", () => ({
9
+ get Clipboard() {
10
+ return native.clipboard;
11
+ },
12
+ }));
3
13
 
4
14
  describe("writeToClipboard", () => {
5
15
  beforeEach(() => {
@@ -22,3 +32,26 @@ describe("writeToClipboard", () => {
22
32
  expect(await writeToClipboard("hello")).toBe(false);
23
33
  });
24
34
  });
35
+
36
+ describe("native writeToClipboard", () => {
37
+ it("writes through the existing React Native clipboard and resolves true", async () => {
38
+ const setString = vi.fn();
39
+ native.clipboard = { setString };
40
+ expect(await writeNativeClipboard("native copy proof")).toBe(true);
41
+ expect(setString).toHaveBeenCalledWith("native copy proof");
42
+ });
43
+
44
+ it("returns false when native copying throws", async () => {
45
+ native.clipboard = {
46
+ setString: () => {
47
+ throw new Error("Clipboard unavailable");
48
+ },
49
+ };
50
+ expect(await writeNativeClipboard("hello")).toBe(false);
51
+ });
52
+
53
+ it("returns false if a future native runtime removes Clipboard", async () => {
54
+ native.clipboard = undefined;
55
+ expect(await writeNativeClipboard("hello")).toBe(false);
56
+ });
57
+ });
@@ -1,2 +1,2 @@
1
- export declare function writeToClipboard(_text: string): Promise<boolean>;
1
+ export declare function writeToClipboard(text: string): Promise<boolean>;
2
2
  //# sourceMappingURL=clipboard.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.native.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.native.ts"],"names":[],"mappings":"AAAA,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEtE"}
1
+ {"version":3,"file":"clipboard.native.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.native.ts"],"names":[],"mappings":"AAEA,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CASrE"}