Skip to content

Commit a974c14

Browse files
Blair Vanderhooffacebook-github-bot
Blair Vanderhoof
authored andcommitted
Add method on YellowBox to ignore warnings
Reviewed By: yungsters Differential Revision: D4979460 fbshipit-source-id: 090a29009a1256809bd975184ad4957b2f6fc36d
1 parent bf0a95d commit a974c14

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Libraries/ReactNative/YellowBox.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type WarningInfo = {
3333

3434
const _warningEmitter = new EventEmitter();
3535
const _warningMap: Map<string, WarningInfo> = new Map();
36+
const IGNORED_WARNINGS: Array<string> = [];
3637

3738
/**
3839
* YellowBox renders warnings at the bottom of the app being developed.
@@ -47,7 +48,11 @@ const _warningMap: Map<string, WarningInfo> = new Map();
4748
* console.disableYellowBox = true;
4849
* console.warn('YellowBox is disabled.');
4950
*
50-
* Warnings can be ignored programmatically by setting the array:
51+
* Ignore specific warnings by calling:
52+
*
53+
* YellowBox.ignoreWarnings(['Warning: ...']);
54+
*
55+
* (DEPRECATED) Warnings can be ignored programmatically by setting the array:
5156
*
5257
* console.ignoredYellowBox = ['Warning: ...'];
5358
*
@@ -153,6 +158,16 @@ function ensureSymbolicatedWarning(warning: string): void {
153158
}
154159

155160
function isWarningIgnored(warning: string): boolean {
161+
const isIgnored =
162+
IGNORED_WARNINGS.some(
163+
(ignoredWarning: string) => warning.startsWith(ignoredWarning)
164+
);
165+
166+
if (isIgnored) {
167+
return true;
168+
}
169+
170+
// DEPRECATED
156171
return (
157172
Array.isArray(console.ignoredYellowBox) &&
158173
console.ignoredYellowBox.some(
@@ -316,6 +331,14 @@ class YellowBox extends React.Component {
316331
};
317332
}
318333

334+
static ignoreWarnings(warnings: Array<string>): void {
335+
warnings.forEach((warning: string) => {
336+
if (IGNORED_WARNINGS.indexOf(warning) === -1) {
337+
IGNORED_WARNINGS.push(warning);
338+
}
339+
});
340+
}
341+
319342
componentDidMount() {
320343
let scheduled = null;
321344
this._listener = _warningEmitter.addListener('warning', warningMap => {

0 commit comments

Comments
 (0)