diff --git a/Libraries/ReactNative/YellowBox.js b/Libraries/ReactNative/YellowBox.js index 458441f80..d6d2514b8 100644 --- a/Libraries/ReactNative/YellowBox.js +++ b/Libraries/ReactNative/YellowBox.js @@ -33,6 +33,7 @@ type WarningInfo = { const _warningEmitter = new EventEmitter(); const _warningMap: Map = new Map(); +const IGNORED_WARNINGS: Array = []; /** * YellowBox renders warnings at the bottom of the app being developed. @@ -47,7 +48,11 @@ const _warningMap: Map = new Map(); * console.disableYellowBox = true; * 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: ...']; * @@ -153,6 +158,16 @@ function ensureSymbolicatedWarning(warning: string): void { } function isWarningIgnored(warning: string): boolean { + const isIgnored = + IGNORED_WARNINGS.some( + (ignoredWarning: string) => warning.startsWith(ignoredWarning) + ); + + if (isIgnored) { + return true; + } + + // DEPRECATED return ( Array.isArray(console.ignoredYellowBox) && console.ignoredYellowBox.some( @@ -316,6 +331,14 @@ class YellowBox extends React.Component { }; } + static ignoreWarnings(warnings: Array): void { + warnings.forEach((warning: string) => { + if (IGNORED_WARNINGS.indexOf(warning) === -1) { + IGNORED_WARNINGS.push(warning); + } + }); + } + componentDidMount() { let scheduled = null; this._listener = _warningEmitter.addListener('warning', warningMap => {