Skip to content

deps: Migrate to @react-native-clipboard/clipboard #5648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ rules:
- devDependencies: ['**/__tests__/**/*.js', tools/**]
no-restricted-imports:
- error
- patterns:
- paths:
- name: 'react-native'
importNames: ['Clipboard']
message: 'Use Clipboard from @react-native-clipboard/clipboard instead.'
patterns:
- group: ['**/__tests__/**']
- group: ['/react-redux']
message: 'Use our own src/react-redux.js instead.'
Expand Down
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ PODS:
- React-Core
- RNCAsyncStorage (1.17.11):
- React-Core
- RNCClipboard (1.11.1):
- React-Core
- RNCMaskedView (0.1.11):
- React
- RNCPushNotificationIOS (1.10.1):
Expand Down Expand Up @@ -529,6 +531,7 @@ DEPENDENCIES:
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
Expand Down Expand Up @@ -664,6 +667,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/rn-fetch-blob"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNCClipboard:
:path: "../node_modules/@react-native-clipboard/clipboard"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNCPushNotificationIOS:
Expand Down Expand Up @@ -749,6 +754,7 @@ SPEC CHECKSUMS:
ReactCommon: 149e2c0acab9bac61378da0db5b2880a1b5ff59b
rn-fetch-blob: f525a73a78df9ed5d35e67ea65e79d53c15255bc
RNCAsyncStorage: 8616bd5a58af409453ea4e1b246521bb76578d60
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNCPushNotificationIOS: 87b8d16d3ede4532745e05b03c42cff33a36cc45
RNDeviceInfo: aad3c663b25752a52bf8fce93f2354001dd185aa
Expand Down
6 changes: 6 additions & 0 deletions jest/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctio
import { URL, URLSearchParams } from 'react-native-url-polyfill';
// $FlowIgnore[untyped-import] - this is not anywhere near critical
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
// $FlowIgnore[untyped-import]
import mockClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock';

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

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

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

// As instructed at
// https://github.com/react-native-clipboard/clipboard/tree/v1.11.1#mocking-clipboard
jest.mock('@react-native-clipboard/clipboard', () => mockClipboard);

// We don't try to actually exercise this module in tests; we just test
// some code in the same module as other code that imports it. Unmocked,
// it complains of missing native modules.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@expo/react-native-action-sheet": "^3.8.0",
"@react-native-async-storage/async-storage": "~1.17.3",
"@react-native-camera-roll/camera-roll": "^5.0.4",
"@react-native-clipboard/clipboard": "^1.11.1",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/netinfo": "6.0.0",
"@react-native-community/push-notification-ios": "^1.5.0",
Expand Down
3 changes: 2 additions & 1 deletion src/RootErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { View, Text, Clipboard, TextInput, ScrollView, Button, Platform } from 'react-native';
import { View, Text, TextInput, ScrollView, Button, Platform } from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';
import Toast from 'react-native-simple-toast';

import * as logging from './utils/logging';
Expand Down
3 changes: 2 additions & 1 deletion src/action-sheets/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import { Clipboard, Share, Alert } from 'react-native';
import { Share, Alert } from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';
import invariant from 'invariant';
import * as resolved_topic from '@zulip/shared/lib/resolved_topic';

Expand Down
3 changes: 2 additions & 1 deletion src/webview/handleOutboundEvents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow strict-local */
import { Clipboard, Alert } from 'react-native';
import { Alert } from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';

import * as api from '../api';
import config from '../config';
Expand Down
4 changes: 4 additions & 0 deletions tools/tsflower
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ run_only()
# TODO get list of packages from data... better yet, make it
# one tsflower command, reading a TsFlower config file

package=@react-native-clipboard/clipboard
run_on_package "${package}"
format_dir "${rootdir}"/types/"${package}"

package=react-native-document-picker
run_on_package "${package}"
format_dir "${rootdir}"/types/"${package}"
Expand Down
24 changes: 24 additions & 0 deletions types/@react-native-clipboard/clipboard/dist/Clipboard.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* @flow
* @generated by TsFlower
*/
import type { EmitterSubscription as $tsflower_subst$RN$EmitterSubscription } from 'tsflower/subst/react-native';
import 'react-native';

declare export var Clipboard: {
getString(): Promise<string>,
getStrings(): Promise<string[]>,
getImagePNG(): Promise<string>,
getImageJPG(): Promise<string>,
setImage(content: string): void,
getImage(): Promise<string>,
setString(content: string): void,
setStrings(content: string[]): void,
hasString(): any,
hasImage(): any,
hasURL(): any,
hasNumber(): any,
hasWebURL(): any,
addListener(callback: () => void): $tsflower_subst$RN$EmitterSubscription,
removeAllListeners(): void,
...
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* @flow
* @generated by TsFlower
*/
import type { EmitterSubscription as $tsflower_subst$RN$EmitterSubscription } from 'tsflower/subst/react-native';
import 'react-native';
declare var _default: any;
export default _default;
declare var addListener: (callback: () => void) => $tsflower_subst$RN$EmitterSubscription;
declare var removeAllListeners: () => void;
export { addListener, removeAllListeners };
6 changes: 6 additions & 0 deletions types/@react-native-clipboard/clipboard/dist/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* @flow
* @generated by TsFlower
*/
import { Clipboard } from './Clipboard';
export { useClipboard } from './useClipboard';
export default Clipboard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* @flow
* @generated by TsFlower
*/
declare export var useClipboard: () => [string, (content: string) => void];
4 changes: 4 additions & 0 deletions types/@react-native-clipboard/clipboard/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* @flow
* @generated
*/
export * from './dist/index.js.flow';
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,11 @@
resolved "https://registry.yarnpkg.com/@react-native-camera-roll/camera-roll/-/camera-roll-5.0.4.tgz#341b8275363ee496b796fa58cb592697798d39e5"
integrity sha512-3kBRgW3VfmLQmQm70gPUVDu8rPSZymoPc9vmeiPLMKBqtWaqPNuPX0jQ6mZ8AEtYbBdoWC360Q4YYPalXv37zA==

"@react-native-clipboard/clipboard@^1.11.1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@react-native-clipboard/clipboard/-/clipboard-1.11.1.tgz#d3a9e685ce2383b1e92b89a334896c5575cc103d"
integrity sha512-nvSIIHzybVWqYxcJE5hpT17ekxAAg383Ggzw5WrYHtkKX61N1AwaKSNmXs5xHV7pmKSOe/yWjtSwxIzfW51I5Q==

"@react-native-community/cli-debugger-ui@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-7.0.3.tgz#3eeeacc5a43513cbcae56e5e965d77726361bcb4"
Expand Down