Expose React Devtools as a Metro plugin

Summary:
This diff turns the DevTools plugin from a normal plugin in a device plugin. The reason for that can be seen at the end of the test plan in the first stack of this diff: Regardless on which client you open the devtools, you are always looking at the react tree of the app that happens to listen at the appropriate port, unrelated to the actively selected app. This diff moves the plugin from being a client plugin to a device plugin, a Metro device plugin to be precisely, as of the latter there is only one and they should typically correspond (which is why we can trigger reload as done in the previous diff)

Currently we have a Flipper plugin inside the iOS / Android apps with one purpose: to select different ports to listen to on different devices. But this functionality was never implemented, nor seems there to be much demand for. So these plugin don't offer any actual value. The widely used standalone version of the react devtools (https://www.npmjs.com/package/react-devtools) doesn't offer port customization either, so this limitation seems to be acceptable.

To make sure that this change is backward compatible, we make sure to show the metro device if we find metro, regardless whether it is new enough to support log forwarding and reload commands (previously we only showed the device if it has the /events endpoint).

The only case I can think of we are killing with this approach is where people are debugging a RN app, but with having metro running. I doubt that is an actual case, but probably rickhanlonii knows more about that.

Furthermore this diff makes sure that the devTools can connect to physical android devices. Also, making it to the end of this explanation means that you have done most of the reviewing for this diff. The actual code diff is shorter.

Reviewed By: passy

Differential Revision: D19878605

fbshipit-source-id: 3f33e59d4f6e4cce39102420f38afee10018999f
This commit is contained in:
Michel Weststrate
2020-02-17 03:36:59 -08:00
committed by Facebook Github Bot
parent 56297d0cfc
commit 1383260a7c
5 changed files with 40 additions and 46 deletions

View File

@@ -13,6 +13,7 @@
#import <FlipperKit/FlipperConnection.h>
#import <FlipperKit/FlipperResponder.h>
// This class is no longer needed, but kept here for backward compatibility
@implementation FlipperKitReactPlugin
- (NSString*)identifier {
@@ -20,10 +21,6 @@
}
- (void)didConnect:(id<FlipperConnection>)connection {
[connection receive:@"config"
withBlock:^(NSDictionary* params, id<FlipperResponder> responder){
// set received port and host to dev tools
}];
}
- (void)didDisconnect {