From c0eddad17b97d0138b3dc8859d1c7dc3bd7c15ae Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Tue, 10 Dec 2019 16:21:37 -0800 Subject: [PATCH] Disable LogBox if native module is not available Summary: Changelog: [Internal] Reviewed By: mmmulani Differential Revision: D18920345 fbshipit-source-id: e5213dc9c3a1aa775138e71a8040a3472e9bbd67 --- Libraries/YellowBox/YellowBox.js | 7 +++++++ Libraries/YellowBox/__tests__/YellowBox-test.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/YellowBox/YellowBox.js b/Libraries/YellowBox/YellowBox.js index ad1b37ab58..4e7587583f 100644 --- a/Libraries/YellowBox/YellowBox.js +++ b/Libraries/YellowBox/YellowBox.js @@ -14,6 +14,8 @@ const React = require('react'); import type {Registry, IgnorePattern} from './Data/YellowBoxRegistry'; import * as LogBoxData from '../LogBox/Data/LogBoxData'; +import NativeLogBox from '../NativeModules/specs/NativeLogBox'; + type Props = $ReadOnly<{||}>; type State = {| registry: ?Registry, @@ -118,6 +120,11 @@ if (__DEV__) { } static __unstable_enableLogBox(): void { + if (NativeLogBox == null) { + // The native module is required to enable LogBox. + return; + } + if (_isInstalled) { throw new Error( 'LogBox must be enabled before AppContainer is required so that it can properly wrap the console methods.\n\nPlease enable LogBox earlier in your app.\n\n', diff --git a/Libraries/YellowBox/__tests__/YellowBox-test.js b/Libraries/YellowBox/__tests__/YellowBox-test.js index acd7e67f98..85eabf1d86 100644 --- a/Libraries/YellowBox/__tests__/YellowBox-test.js +++ b/Libraries/YellowBox/__tests__/YellowBox-test.js @@ -16,7 +16,7 @@ const YellowBox = require('../YellowBox'); const YellowBoxRegistry = require('../Data/YellowBoxRegistry'); const LogBoxData = require('../../LogBox/Data/LogBoxData'); const render = require('../../../jest/renderer'); - +jest.mock('../../NativeModules/specs/NativeLogBox', () => true); jest.mock('../../LogBox/LogBoxNotificationContainer', () => ({ __esModule: true, default: 'LogBoxNotificationContainer',