Skip to content

Commit

Permalink
Warn that 'WebView' has moved to 'react-native-webview'
Browse files Browse the repository at this point in the history
  • Loading branch information
empyrical committed Nov 4, 2018
1 parent cc13a73 commit 35495d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Libraries/Utilities/warnMoved.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

'use strict';

const warning = require('fbjs/lib/warning');

const warnedApis: {[string]: boolean} = {};

/**
* A simple function that warns the user once if an API has been moved to
* another module.
*
* @param {string} api - The name of the API or component that moved
* @param {string} destModule - The name of the module that the API moved to
* @param {string} [renamed] - Optional; name of the API in the dest module,
* if it was renamed
*/
function warnMoved(api: string, destModule: string, renamed?: string) {
if (warnedApis[api]) {
return;
}

const destName = renamed != null ? renamed : api;

warning(
false,
`'${api}' has moved to another module and will be removed from 'react-native' ` +
`in a future release. You can instead import it from the module '${destModule}':` +
`\n import {${destName}} from '${destModule}';`,
);

warnedApis[api] = true;
}

module.exports = warnMoved;
2 changes: 2 additions & 0 deletions Libraries/react-native/react-native-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'use strict';

const invariant = require('fbjs/lib/invariant');
const warnMoved = require('warnMoved');

let showedListViewDeprecation = false;
let showedSwipeableListViewDeprecation = false;
Expand Down Expand Up @@ -170,6 +171,7 @@ module.exports = {
return require('VirtualizedList');
},
get WebView() {
warnMoved('WebView', 'react-native-webview');
return require('WebView');
},

Expand Down

0 comments on commit 35495d3

Please sign in to comment.