Don't die when flipper isn't initialized and a plugin is used

Summary: This diff makes sure that the app doesn't die, or dies in a meaningful way if things are misconfigured.

Reviewed By: passy

Differential Revision: D19468273

fbshipit-source-id: 2471c263391906113446af57d795d1199eb1730e
This commit is contained in:
Michel Weststrate
2020-01-23 07:09:51 -08:00
committed by Facebook Github Bot
parent 0fa0899299
commit e306aeb010
4 changed files with 38 additions and 5 deletions

View File

@@ -125,6 +125,10 @@ function startEventListeners() {
// $FlowFixMe
export function addPlugin(plugin) {
if (!Flipper) {
printNoFlipperWarning();
return;
}
if (!plugin || typeof plugin !== 'object') {
throw new Error('Expected plugin, got ' + plugin);
}
@@ -141,7 +145,22 @@ export function addPlugin(plugin) {
plugin._connection = new Connection(id);
plugins[id] = plugin;
Flipper.registerPlugin(id, runInBackground);
Flipper.registerPlugin(id, runInBackground, status => {
if (status === 'noflipper') {
printNoFlipperWarning();
}
});
}
startEventListeners();
function printNoFlipperWarning() {
// $FlowFixMe
if (typeof __DEV__ !== 'undefined' && __DEV__) {
console.warn(
'The native module for Flipper seems unavailable. Make sure `initializeFlipper(this, getReactNativeHost().getReactInstanceManager()` is called in MainApplication.java:onCreate, and that `react-native-flipper` is installed as yarn dependency',
);
}
}
if (Flipper) {
startEventListeners();
}