Skip to content

Commit 35495d3

Browse files
committed
Warn that 'WebView' has moved to 'react-native-webview'
1 parent cc13a73 commit 35495d3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Libraries/Utilities/warnMoved.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
const warning = require('fbjs/lib/warning');
14+
15+
const warnedApis: {[string]: boolean} = {};
16+
17+
/**
18+
* A simple function that warns the user once if an API has been moved to
19+
* another module.
20+
*
21+
* @param {string} api - The name of the API or component that moved
22+
* @param {string} destModule - The name of the module that the API moved to
23+
* @param {string} [renamed] - Optional; name of the API in the dest module,
24+
* if it was renamed
25+
*/
26+
function warnMoved(api: string, destModule: string, renamed?: string) {
27+
if (warnedApis[api]) {
28+
return;
29+
}
30+
31+
const destName = renamed != null ? renamed : api;
32+
33+
warning(
34+
false,
35+
`'${api}' has moved to another module and will be removed from 'react-native' ` +
36+
`in a future release. You can instead import it from the module '${destModule}':` +
37+
`\n import {${destName}} from '${destModule}';`,
38+
);
39+
40+
warnedApis[api] = true;
41+
}
42+
43+
module.exports = warnMoved;

Libraries/react-native/react-native-implementation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'use strict';
1212

1313
const invariant = require('fbjs/lib/invariant');
14+
const warnMoved = require('warnMoved');
1415

1516
let showedListViewDeprecation = false;
1617
let showedSwipeableListViewDeprecation = false;
@@ -170,6 +171,7 @@ module.exports = {
170171
return require('VirtualizedList');
171172
},
172173
get WebView() {
174+
warnMoved('WebView', 'react-native-webview');
173175
return require('WebView');
174176
},
175177

0 commit comments

Comments
 (0)