@@ -33,6 +33,7 @@ type WarningInfo = {
33
33
34
34
const _warningEmitter = new EventEmitter ( ) ;
35
35
const _warningMap : Map < string , WarningInfo > = new Map ( ) ;
36
+ const IGNORED_WARNINGS : Array < string > = [];
36
37
37
38
/**
38
39
* YellowBox renders warnings at the bottom of the app being developed.
@@ -47,7 +48,11 @@ const _warningMap: Map<string, WarningInfo> = new Map();
47
48
* console.disableYellowBox = true;
48
49
* console.warn('YellowBox is disabled.');
49
50
*
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:
51
56
*
52
57
* console.ignoredYellowBox = ['Warning: ...'];
53
58
*
@@ -153,6 +158,16 @@ function ensureSymbolicatedWarning(warning: string): void {
153
158
}
154
159
155
160
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
156
171
return (
157
172
Array . isArray ( console . ignoredYellowBox ) &&
158
173
console . ignoredYellowBox . some (
@@ -316,6 +331,14 @@ class YellowBox extends React.Component {
316
331
} ;
317
332
}
318
333
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
+
319
342
componentDidMount() {
320
343
let scheduled = null ;
321
344
this . _listener = _warningEmitter . addListener ( 'warning' , warningMap => {
0 commit comments