Skip to content

Commit 418fc56

Browse files
authored
Remove deprecated Clipboard from the public API
## Summary: `Clipboard` has been deprecated since it moved to [`@react-native-clipboard/clipboard`](https://github.com/react-native-clipboard/clipboard). This PR removes it from the public API. LogBox still uses it to copy logs, so I kept the internal module and the native modules. In dev, accessing `Clipboard` from `react-native` now throws an error that points to the community package. ## Changelog: [GENERAL] [BREAKING] - Remove deprecated `Clipboard` from the public API ## Test Plan: Commands I ran, and their results: - `yarn flow-check`: 0 errors - `yarn build-types && yarn test-generated-typescript`: passed - `yarn eslint` on changed JS files: clean - `yarn test packages/eslint-plugin-react-native packages/react-native-babel-preset packages/react-native/Libraries/LogBox`: 270 tests passed Differential Revision: D129616273 Pull Request resolved: #59062
1 parent a8491cc commit 418fc56

7 files changed

Lines changed: 17 additions & 52 deletions

File tree

‎packages/eslint-plugin-react-native/utils.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ const publicAPIMapping = {
8686
default: 'Button',
8787
types: ['ButtonInstance', 'ButtonProps'],
8888
},
89-
'Libraries/Components/Clipboard/Clipboard': {
90-
default: 'Clipboard',
91-
types: null,
92-
},
9389
'Libraries/Components/DrawerAndroid/DrawerLayoutAndroid': {
9490
default: 'DrawerLayoutAndroid',
9591
types: null,

‎packages/react-native-babel-preset/src/configs/lazy-imports.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ module.exports = new Set([
5656
'AppState',
5757
'AsyncStorage',
5858
'BackHandler',
59-
'Clipboard',
6059
'DeviceInfo',
6160
'Dimensions',
6261
'Easing',

‎packages/react-native/ReactNativeApi.d.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<57a22e3b7e5bbdb70ec787177e97ef4b>>
7+
* @generated SignedSource<<0ec86f273125a0f5d0e47bc71371b776>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -164,10 +164,6 @@ declare const Button_default: (
164164
ref?: React.Ref<ButtonInstance>
165165
},
166166
) => React.ReactNode
167-
declare const Clipboard: {
168-
getString(): Promise<string>
169-
setString(content: string): void
170-
}
171167
declare const codegenNativeCommands: typeof codegenNativeCommands_default
172168
declare const codegenNativeComponent: typeof codegenNativeComponent_default
173169
declare const compose: typeof composeStyles_default
@@ -1726,7 +1722,6 @@ declare class CellRenderMask {
17261722
equals(other: CellRenderMask): boolean
17271723
numCells(): number
17281724
}
1729-
declare type Clipboard = typeof Clipboard
17301725
declare type codegenNativeCommands = typeof codegenNativeCommands
17311726
declare function codegenNativeCommands_default<T extends {}>(
17321727
options: NativeCommandsOptions<keyof T & string>,
@@ -5814,7 +5809,6 @@ export {
58145809
Button, // f253fc94
58155810
ButtonInstance, // bcf2ef72
58165811
ButtonProps, // 9886bcc6
5817-
Clipboard, // 41addb89
58185812
CodegenTypes, // 9067fd06
58195813
ColorSchemeName, // 6615edd6
58205814
ColorValue, // 98989a8f

‎packages/react-native/index.js‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ module.exports = {
256256
get BackHandler() {
257257
return require('./Libraries/Utilities/BackHandler').default;
258258
},
259-
get Clipboard() {
260-
warnOnce(
261-
'clipboard-moved',
262-
'Clipboard has been extracted from react-native core and will be removed in a future release. ' +
263-
"It can now be installed and imported from '@react-native-clipboard/clipboard' instead of 'react-native'. " +
264-
'See https://github.com/react-native-clipboard/clipboard',
265-
);
266-
return require('./Libraries/Components/Clipboard/Clipboard').default;
267-
},
268259
get codegenNativeCommands() {
269260
return require('./Libraries/Utilities/codegenNativeCommands').default;
270261
},
@@ -466,4 +457,20 @@ if (__DEV__) {
466457
);
467458
},
468459
});
460+
461+
/* $FlowFixMe[prop-missing] This is intentional: Flow will error when
462+
* attempting to access Clipboard. */
463+
/* $FlowFixMe[invalid-export] This is intentional: Flow will error when
464+
* attempting to access Clipboard. */
465+
Object.defineProperty(module.exports, 'Clipboard', {
466+
configurable: true,
467+
get() {
468+
invariant(
469+
false,
470+
'Clipboard has been removed from react-native core. ' +
471+
"It can now be installed and imported from '@react-native-clipboard/clipboard' instead of 'react-native'. " +
472+
'See https://github.com/react-native-clipboard/clipboard',
473+
);
474+
},
475+
});
469476
}

‎packages/react-native/index.js.flow‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ export type {
297297
export type {BackPressEventName} from './Libraries/Utilities/BackHandler';
298298
export {default as BackHandler} from './Libraries/Utilities/BackHandler';
299299

300-
export {default as Clipboard} from './Libraries/Components/Clipboard/Clipboard';
301-
302300
export {default as codegenNativeComponent} from './Libraries/Utilities/codegenNativeComponent';
303301
export {default as codegenNativeCommands} from './Libraries/Utilities/codegenNativeCommands';
304302

‎packages/react-native/types_DEPRECATED/Libraries/Components/Clipboard/Clipboard.d.ts‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎packages/react-native/types_DEPRECATED/index.d.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export * from './Libraries/AppState/AppState';
8181
export * from './Libraries/BatchedBridge/NativeModules';
8282
export * from './Libraries/Components/AccessibilityInfo/AccessibilityInfo';
8383
export * from './Libraries/Components/ActivityIndicator/ActivityIndicator';
84-
export * from './Libraries/Components/Clipboard/Clipboard';
8584
export * from './Libraries/Components/DrawerAndroid/DrawerLayoutAndroid';
8685
export * from './Libraries/Components/Keyboard/Keyboard';
8786
export * from './Libraries/Components/Keyboard/KeyboardAvoidingView';

0 commit comments

Comments
 (0)