mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 13:25:51 +08:00
Add method on YellowBox to ignore warnings
Reviewed By: yungsters Differential Revision: D4979460 fbshipit-source-id: 090a29009a1256809bd975184ad4957b2f6fc36d
This commit is contained in:
committed by
Facebook Github Bot
parent
bf0a95d338
commit
a974c140db
@@ -33,6 +33,7 @@ type WarningInfo = {
|
|||||||
|
|
||||||
const _warningEmitter = new EventEmitter();
|
const _warningEmitter = new EventEmitter();
|
||||||
const _warningMap: Map<string, WarningInfo> = new Map();
|
const _warningMap: Map<string, WarningInfo> = new Map();
|
||||||
|
const IGNORED_WARNINGS: Array<string> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YellowBox renders warnings at the bottom of the app being developed.
|
* YellowBox renders warnings at the bottom of the app being developed.
|
||||||
@@ -47,7 +48,11 @@ const _warningMap: Map<string, WarningInfo> = new Map();
|
|||||||
* console.disableYellowBox = true;
|
* console.disableYellowBox = true;
|
||||||
* console.warn('YellowBox is disabled.');
|
* console.warn('YellowBox is disabled.');
|
||||||
*
|
*
|
||||||
* Warnings can be ignored programmatically by setting the array:
|
* Ignore specific warnings by calling:
|
||||||
|
*
|
||||||
|
* YellowBox.ignoreWarnings(['Warning: ...']);
|
||||||
|
*
|
||||||
|
* (DEPRECATED) Warnings can be ignored programmatically by setting the array:
|
||||||
*
|
*
|
||||||
* console.ignoredYellowBox = ['Warning: ...'];
|
* console.ignoredYellowBox = ['Warning: ...'];
|
||||||
*
|
*
|
||||||
@@ -153,6 +158,16 @@ function ensureSymbolicatedWarning(warning: string): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isWarningIgnored(warning: string): boolean {
|
function isWarningIgnored(warning: string): boolean {
|
||||||
|
const isIgnored =
|
||||||
|
IGNORED_WARNINGS.some(
|
||||||
|
(ignoredWarning: string) => warning.startsWith(ignoredWarning)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isIgnored) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEPRECATED
|
||||||
return (
|
return (
|
||||||
Array.isArray(console.ignoredYellowBox) &&
|
Array.isArray(console.ignoredYellowBox) &&
|
||||||
console.ignoredYellowBox.some(
|
console.ignoredYellowBox.some(
|
||||||
@@ -316,6 +331,14 @@ class YellowBox extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ignoreWarnings(warnings: Array<string>): void {
|
||||||
|
warnings.forEach((warning: string) => {
|
||||||
|
if (IGNORED_WARNINGS.indexOf(warning) === -1) {
|
||||||
|
IGNORED_WARNINGS.push(warning);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let scheduled = null;
|
let scheduled = null;
|
||||||
this._listener = _warningEmitter.addListener('warning', warningMap => {
|
this._listener = _warningEmitter.addListener('warning', warningMap => {
|
||||||
|
|||||||
Reference in New Issue
Block a user