@@ -33,6 +33,7 @@ type WarningInfo = {
3333
3434const _warningEmitter = new EventEmitter ( ) ;
3535const _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
155160function 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