@react-native-clipboard/clipboard 1.11.1 → 1.12.1

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.
@@ -69,7 +69,7 @@ public class ClipboardModule extends ReactContextBaseJavaModule {
69
69
  ClipboardManager clipboard = getClipboardService();
70
70
  ClipData clipData = clipboard.getPrimaryClip();
71
71
  if (clipData != null && clipData.getItemCount() >= 1) {
72
- ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0);
72
+ ClipData.Item firstItem = clipData.getItemAt(0);
73
73
  promise.resolve("" + firstItem.getText());
74
74
  } else {
75
75
  promise.resolve("");
@@ -90,7 +90,7 @@ export declare const Clipboard: {
90
90
  * }
91
91
  * ```
92
92
  */
93
- hasString(): any;
93
+ hasString(): Promise<boolean>;
94
94
  /**
95
95
  * Returns whether the clipboard has an image or is empty.
96
96
  * This method returns a `Promise`, so you can use following code to check clipboard content
@@ -100,7 +100,7 @@ export declare const Clipboard: {
100
100
  * }
101
101
  * ```
102
102
  */
103
- hasImage(): any;
103
+ hasImage(): Promise<boolean>;
104
104
  /**
105
105
  * (iOS Only)
106
106
  * Returns whether the clipboard has a URL content. Can check
@@ -112,7 +112,7 @@ export declare const Clipboard: {
112
112
  * }
113
113
  * ```
114
114
  */
115
- hasURL(): any;
115
+ hasURL(): Promise<boolean> | undefined;
116
116
  /**
117
117
  * (iOS 14+ Only)
118
118
  * Returns whether the clipboard has a Number(UIPasteboardDetectionPatternNumber) content. Can check
@@ -124,7 +124,7 @@ export declare const Clipboard: {
124
124
  * }
125
125
  * ```
126
126
  */
127
- hasNumber(): any;
127
+ hasNumber(): Promise<boolean> | undefined;
128
128
  /**
129
129
  * (iOS 14+ Only)
130
130
  * Returns whether the clipboard has a WebURL(UIPasteboardDetectionPatternProbableWebURL) content. Can check
@@ -136,7 +136,7 @@ export declare const Clipboard: {
136
136
  * }
137
137
  * ```
138
138
  */
139
- hasWebURL(): any;
139
+ hasWebURL(): Promise<boolean> | undefined;
140
140
  /**
141
141
  * (iOS and Android Only)
142
142
  * Adds a listener to get notifications when the clipboard has changed.
@@ -1,5 +1,22 @@
1
1
  import { EmitterSubscription } from 'react-native';
2
- declare const _default: any;
2
+ import type { TurboModule } from 'react-native';
3
+ export interface Spec extends TurboModule {
4
+ getConstants: () => {};
5
+ getString: () => Promise<string>;
6
+ getStrings: () => Promise<string[]>;
7
+ setString: (content: string) => void;
8
+ hasString: () => Promise<boolean>;
9
+ hasNumber: () => Promise<boolean>;
10
+ getImagePNG: () => Promise<string>;
11
+ getImageJPG: () => Promise<string>;
12
+ setImage: (content: string) => void;
13
+ getImage: () => Promise<string>;
14
+ setStrings: (content: string[]) => void;
15
+ hasImage: () => Promise<boolean>;
16
+ hasURL: () => Promise<boolean>;
17
+ hasWebURL: () => Promise<boolean>;
18
+ }
19
+ declare const _default: Spec;
3
20
  export default _default;
4
21
  declare const addListener: (callback: () => void) => EmitterSubscription;
5
22
  declare const removeAllListeners: () => void;
@@ -2,15 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeAllListeners = exports.addListener = void 0;
4
4
  var react_native_1 = require("react-native");
5
- // Separated file for Native Clipboard to be ready to switch to Turbo Module when it becomes public
6
- // TODO: uncomment when Turbo module is available
7
- // export interface Spec extends TurboModule {
8
- // +getConstants: () => {||};
9
- // +getString: () => Promise<string>;
10
- // +setString: (content: string) => void;
11
- // +hasString: () => Promise<boolean>;
12
- // }
13
- exports.default = react_native_1.NativeModules.RNCClipboard;
5
+ exports.default = react_native_1.TurboModuleRegistry.get('RNCClipboard');
14
6
  var EVENT_NAME = 'RNCClipboard_TEXT_CHANGED';
15
7
  var eventEmitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNCClipboard);
16
8
  var listenerCount = eventEmitter.listenerCount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-clipboard/clipboard",
3
- "version": "1.11.1",
3
+ "version": "1.12.1",
4
4
  "description": "React Native Clipboard API for macOS, iOS, Android, and Windows",
5
5
  "keywords": [
6
6
  "Clipboard",
@@ -47,7 +47,7 @@
47
47
  "devDependencies": {
48
48
  "@babel/core": "^7.12.9",
49
49
  "@react-native-community/eslint-config": "^2.0.0",
50
- "@types/react-native": "^0.64.8",
50
+ "@types/react-native": "^0.70.0",
51
51
  "babel-jest": "^26.1.0",
52
52
  "eslint": "^7.32.0",
53
53
  "eslint-plugin-prettier": "^3.1.2",
@@ -55,7 +55,7 @@
55
55
  "metro-react-native-babel-preset": "^0.64.0",
56
56
  "prettier": "^2.4.1",
57
57
  "react": "17.0.1",
58
- "react-native": "0.64.1",
58
+ "react-native": "0.68.0",
59
59
  "react-native-macos": "^0.62.0-0",
60
60
  "react-native-windows": "^0.64.0",
61
61
  "react-test-renderer": "16.9.0",
@@ -67,5 +67,13 @@
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"
70
+ },
71
+ "codegenConfig": {
72
+ "name": "RNCClipboard",
73
+ "type": "all",
74
+ "jsSrcsDir": ".",
75
+ "android": {
76
+ "javaPackageName": "com.reactnativecommunity.clipboard"
77
+ }
70
78
  }
71
79
  }
@@ -8,7 +8,7 @@ namespace NativeClipboard {
8
8
  if (dataPackageView.Contains(datatransfer::StandardDataFormats::Text())) {
9
9
  dataPackageView.GetTextAsync().Completed([promise, dataPackageView](IAsyncOperation<winrt::hstring> info, AsyncStatus status) {
10
10
  if (status == AsyncStatus::Completed) {
11
- auto text = Microsoft::Common::Unicode::Utf16ToUtf8(info.GetResults());
11
+ auto text = winrt::to_string(info.GetResults());
12
12
  promise.Resolve(text);
13
13
  }
14
14
  else {
@@ -22,8 +22,23 @@ namespace NativeClipboard {
22
22
 
23
23
  void ClipboardModule::SetString(std::string const& str) noexcept
24
24
  {
25
- datatransfer::DataPackage dataPackage{};
26
- dataPackage.SetText(Microsoft::Common::Unicode::Utf8ToUtf16(str));
27
- datatransfer::Clipboard::SetContent(dataPackage);
25
+ _context.UIDispatcher().Post([str](){
26
+ datatransfer::DataPackage dataPackage{};
27
+ dataPackage.SetText(winrt::to_hstring(str));
28
+ datatransfer::Clipboard::SetContent(dataPackage);
29
+ });
30
+ }
31
+
32
+ void ClipboardModule::AddListener(std::string const& event) noexcept
33
+ {
34
+ _listenerCount++;
35
+ }
36
+
37
+ void ClipboardModule::RemoveListeners(int count) noexcept
38
+ {
39
+ _listenerCount--;
40
+ if (_listenerCount == 0) {
41
+ // Disconnect any native eventing here
42
+ }
28
43
  }
29
44
  }
@@ -16,11 +16,26 @@ namespace NativeClipboard {
16
16
  REACT_MODULE(ClipboardModule, L"RNCClipboard");
17
17
  struct ClipboardModule
18
18
  {
19
+ REACT_INIT(Initialize);
20
+ void Initialize(const winrt::Microsoft::ReactNative::ReactContext& reactContext) noexcept
21
+ {
22
+ _context = reactContext;
23
+ }
19
24
 
20
25
  REACT_METHOD(GetString, L"getString");
21
26
  void GetString(React::ReactPromise<std::string>&& result) noexcept;
22
27
 
23
28
  REACT_METHOD(SetString, L"setString");
24
29
  void SetString(std::string const& str) noexcept;
30
+
31
+ REACT_METHOD(AddListener, L"addListener");
32
+ void AddListener(std::string const& event) noexcept;
33
+
34
+ REACT_METHOD(RemoveListeners, L"removeListeners");
35
+ void RemoveListeners(int count) noexcept;
36
+
37
+ private:
38
+ int _listenerCount = 0;
39
+ ReactContext _context;
25
40
  };
26
41
  }
@@ -14,8 +14,14 @@
14
14
  <AppContainerApplication>true</AppContainerApplication>
15
15
  <ApplicationType>Windows Store</ApplicationType>
16
16
  <ApplicationTypeRevision>10.0</ApplicationTypeRevision>
17
- <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
18
- <WindowsTargetPlatformMinVersion>10.0.17134.0</WindowsTargetPlatformMinVersion>
17
+ </PropertyGroup>
18
+ <PropertyGroup Label="ReactNativeWindowsProps">
19
+ <ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
20
+ </PropertyGroup>
21
+ <Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.WindowsSdk.Default.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.WindowsSdk.Default.props')" />
22
+ <PropertyGroup Label="Fallback Windows SDK Versions">
23
+ <WindowsTargetPlatformVersion Condition=" '$(WindowsTargetPlatformVersion)' == '' ">10.0.18362.0</WindowsTargetPlatformVersion>
24
+ <WindowsTargetPlatformMinVersion Condition=" '$(WindowsTargetPlatformMinVersion)' == '' ">10.0.17763.0</WindowsTargetPlatformMinVersion>
19
25
  </PropertyGroup>
20
26
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21
27
  <ItemGroup Label="ProjectConfigurations">
@@ -54,9 +60,6 @@
54
60
  </ItemGroup>
55
61
  <PropertyGroup Label="Configuration">
56
62
  <ConfigurationType>DynamicLibrary</ConfigurationType>
57
- <PlatformToolset>v140</PlatformToolset>
58
- <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
59
- <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
60
63
  <CharacterSet>Unicode</CharacterSet>
61
64
  <GenerateManifest>false</GenerateManifest>
62
65
  </PropertyGroup>
@@ -72,9 +75,6 @@
72
75
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
73
76
  <ImportGroup Label="ExtensionSettings">
74
77
  </ImportGroup>
75
- <PropertyGroup>
76
- <ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
77
- </PropertyGroup>
78
78
  <ImportGroup Label="Shared">
79
79
  <Import Project="$(ReactNativeWindowsDir)\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems" Label="Shared" />
80
80
  </ImportGroup>