Skip to content

Commit b63e822

Browse files
chrisbobberajprakash00
authored andcommitted
deps: Migrate to @react-native-clipboard/clipboard
`Clipboard` in RN core has been deprecated for a while, and in RN's v0.71 doc they finally mark it "removed": https://reactnative.dev/docs/clipboard We've reportedly (#4502) been getting console warnings that we should use @react-native-community/clipboard instead of the RN-core module. Do basically that, except we use its new name, @react-native-clipboard/clipboard; see react-native-clipboard/clipboard#87 Supersedes: #4502 Co-authored-by: rajprakash00 <[email protected]>
1 parent 9716c9e commit b63e822

File tree

14 files changed

+81
-4
lines changed

14 files changed

+81
-4
lines changed

.eslintrc.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ rules:
280280
- devDependencies: ['**/__tests__/**/*.js', tools/**]
281281
no-restricted-imports:
282282
- error
283-
- patterns:
283+
- paths:
284+
- name: 'react-native'
285+
importNames: ['Clipboard']
286+
message: 'Use Clipboard from @react-native-clipboard/clipboard instead.'
287+
patterns:
284288
- group: ['**/__tests__/**']
285289
- group: ['/react-redux']
286290
message: 'Use our own src/react-redux.js instead.'

ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ PODS:
398398
- React-Core
399399
- RNCAsyncStorage (1.17.11):
400400
- React-Core
401+
- RNCClipboard (1.11.1):
402+
- React-Core
401403
- RNCMaskedView (0.1.11):
402404
- React
403405
- RNCPushNotificationIOS (1.10.1):
@@ -529,6 +531,7 @@ DEPENDENCIES:
529531
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
530532
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
531533
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
534+
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
532535
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
533536
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
534537
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
@@ -664,6 +667,8 @@ EXTERNAL SOURCES:
664667
:path: "../node_modules/rn-fetch-blob"
665668
RNCAsyncStorage:
666669
:path: "../node_modules/@react-native-async-storage/async-storage"
670+
RNCClipboard:
671+
:path: "../node_modules/@react-native-clipboard/clipboard"
667672
RNCMaskedView:
668673
:path: "../node_modules/@react-native-community/masked-view"
669674
RNCPushNotificationIOS:
@@ -749,6 +754,7 @@ SPEC CHECKSUMS:
749754
ReactCommon: 149e2c0acab9bac61378da0db5b2880a1b5ff59b
750755
rn-fetch-blob: f525a73a78df9ed5d35e67ea65e79d53c15255bc
751756
RNCAsyncStorage: 8616bd5a58af409453ea4e1b246521bb76578d60
757+
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
752758
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
753759
RNCPushNotificationIOS: 87b8d16d3ede4532745e05b03c42cff33a36cc45
754760
RNDeviceInfo: aad3c663b25752a52bf8fce93f2354001dd185aa

jest/jestSetup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctio
55
import { URL, URLSearchParams } from 'react-native-url-polyfill';
66
// $FlowIgnore[untyped-import] - this is not anywhere near critical
77
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
8+
// $FlowIgnore[untyped-import]
9+
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock';
810

911
import { assertUsingFakeTimers } from '../src/__tests__/lib/fakeTimers';
1012

@@ -102,6 +104,10 @@ jest.mock('react-native-reanimated', () => {
102104

103105
jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage);
104106

107+
// As instructed at
108+
// https://github.com/react-native-clipboard/clipboard/tree/v1.11.1#mocking-clipboard
109+
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);
110+
105111
// We don't try to actually exercise this module in tests; we just test
106112
// some code in the same module as other code that imports it. Unmocked,
107113
// it complains of missing native modules.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@expo/react-native-action-sheet": "^3.8.0",
2626
"@react-native-async-storage/async-storage": "~1.17.3",
2727
"@react-native-camera-roll/camera-roll": "^5.0.4",
28+
"@react-native-clipboard/clipboard": "^1.11.1",
2829
"@react-native-community/masked-view": "^0.1.10",
2930
"@react-native-community/netinfo": "6.0.0",
3031
"@react-native-community/push-notification-ios": "^1.5.0",

src/RootErrorBoundary.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* @flow strict-local */
22
import React from 'react';
33
import type { Node } from 'react';
4-
import { View, Text, Clipboard, TextInput, ScrollView, Button, Platform } from 'react-native';
4+
import { View, Text, TextInput, ScrollView, Button, Platform } from 'react-native';
5+
import Clipboard from '@react-native-clipboard/clipboard';
56
import Toast from 'react-native-simple-toast';
67

78
import * as logging from './utils/logging';

src/action-sheets/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow strict-local */
2-
import { Clipboard, Share, Alert } from 'react-native';
2+
import { Share, Alert } from 'react-native';
3+
import Clipboard from '@react-native-clipboard/clipboard';
34
import invariant from 'invariant';
45
import * as resolved_topic from '@zulip/shared/lib/resolved_topic';
56

src/webview/handleOutboundEvents.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow strict-local */
2-
import { Clipboard, Alert } from 'react-native';
2+
import { Alert } from 'react-native';
3+
import Clipboard from '@react-native-clipboard/clipboard';
34

45
import * as api from '../api';
56
import config from '../config';

tools/tsflower

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ run_only()
147147
# TODO get list of packages from data... better yet, make it
148148
# one tsflower command, reading a TsFlower config file
149149

150+
package=@react-native-clipboard/clipboard
151+
run_on_package "${package}"
152+
format_dir "${rootdir}"/types/"${package}"
153+
150154
package=react-native-document-picker
151155
run_on_package "${package}"
152156
format_dir "${rootdir}"/types/"${package}"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* @flow
2+
* @generated by TsFlower
3+
*/
4+
import type { EmitterSubscription as $tsflower_subst$RN$EmitterSubscription } from 'tsflower/subst/react-native';
5+
import 'react-native';
6+
7+
declare export var Clipboard: {
8+
getString(): Promise<string>,
9+
getStrings(): Promise<string[]>,
10+
getImagePNG(): Promise<string>,
11+
getImageJPG(): Promise<string>,
12+
setImage(content: string): void,
13+
getImage(): Promise<string>,
14+
setString(content: string): void,
15+
setStrings(content: string[]): void,
16+
hasString(): any,
17+
hasImage(): any,
18+
hasURL(): any,
19+
hasNumber(): any,
20+
hasWebURL(): any,
21+
addListener(callback: () => void): $tsflower_subst$RN$EmitterSubscription,
22+
removeAllListeners(): void,
23+
...
24+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* @flow
2+
* @generated by TsFlower
3+
*/
4+
import type { EmitterSubscription as $tsflower_subst$RN$EmitterSubscription } from 'tsflower/subst/react-native';
5+
import 'react-native';
6+
declare var _default: any;
7+
export default _default;
8+
declare var addListener: (callback: () => void) => $tsflower_subst$RN$EmitterSubscription;
9+
declare var removeAllListeners: () => void;
10+
export { addListener, removeAllListeners };

0 commit comments

Comments
 (0)