diff --git a/docs/extending/create-plugin.md b/docs/extending/create-plugin.md index 0b2cebd1a..4540c8bca 100644 --- a/docs/extending/create-plugin.md +++ b/docs/extending/create-plugin.md @@ -7,8 +7,9 @@ title: Mobile Setup Create a class implementing `FlipperPlugin`. The ID that is returned from your implementation needs to match the `name` defined in your JavaScript counterpart's `package.json`. -### Android + + ```java public class MyFlipperPlugin implements FlipperPlugin { private FlipperConnection mConnection; @@ -34,9 +35,7 @@ public class MyFlipperPlugin implements FlipperPlugin { } } ``` - -### iOS - + ```objective-c @interface MyFlipperPlugin : NSObject @end @@ -50,9 +49,7 @@ public class MyFlipperPlugin implements FlipperPlugin { @end ``` - -### C++ - + ```c++ class MyFlipperPlugin : public FlipperPlugin { public: @@ -62,13 +59,15 @@ public: bool runInBackground() override; }; ``` + + ## Using FlipperConnection Using the `FlipperConnection` object you can register a receiver of a desktop method call and respond with data. -### Android - + + ```java connection.receive("getData", new FlipperReceiver() { @Override @@ -80,9 +79,7 @@ connection.receive("getData", new FlipperReceiver() { } }); ``` - -### iOS - + ```objective-c @interface MyFlipperPlugin : NSObject @end @@ -104,9 +101,7 @@ connection.receive("getData", new FlipperReceiver() { @end ``` - -### C++ - + ```c++ void MyFlipperPlugin::didConnect(std::shared_ptr conn) { conn->receive("getData", [](const folly::dynamic ¶ms, @@ -116,34 +111,32 @@ void MyFlipperPlugin::didConnect(std::shared_ptr conn) { }); } ``` + ## Push data to the desktop You don't have to wait for the desktop to request data though, you can also push data directly to the desktop. -### Android - + + ```java connection.send("MyMessage", new FlipperObject.Builder() .put("message", "Hello") .build() ``` - -### iOS - + ```objective-c [connection send:@"getData" withParams:@{@"message":@"hello"}]; ``` - -### C++ - + ```c++ void MyFlipperPlugin::didConnect(std::shared_ptr conn) { dynamic message = folly::dynamic::object("message", "hello"); conn->send("getData", message); } ``` + ## Background Plugins diff --git a/docs/extending/send-data.md b/docs/extending/send-data.md index cefa26c0f..068c69526 100644 --- a/docs/extending/send-data.md +++ b/docs/extending/send-data.md @@ -9,8 +9,9 @@ Plugins should be treated as singleton instances as there can only be one `Flipp Plugins are identified by the string that their identifier method returns, in this example, "MyFlipperPlugin": -### Android + + ```java final FlipperClient client = AndroidFlipperClient.getInstance(context); // Client may be null if AndroidFlipperClient.createInstance() was never called @@ -20,17 +21,13 @@ if (client != null) { plugin.sendData(myData); } ``` - -### iOS - + ```objective-c FlipperClient *client = [FlipperClient sharedClient]; MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"]; [myPlugin sendData:myData]; ``` - -### C++ - + ```c++ auto &client = FlipperClient::instance(); @@ -45,5 +42,8 @@ myPlugin = client.getPlugin("MyFlipperPlugin"); myPlugin->sendData(myData); ``` +``` + + Here, `sendData` is an example of a method that might be implemented by the Flipper plugin.