Summary: Seems that all tabs were broken after migration to Docusaurus 2. Reviewed By: jknoxville Differential Revision: D25586214 fbshipit-source-id: 31a8da4e13fbac01911a03f1f4bab0d2837c9c9a
50 lines
1.6 KiB
Plaintext
50 lines
1.6 KiB
Plaintext
---
|
|
id: send-data
|
|
title: Providing Data to Plugins
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
It is often useful to get an instance of a Flipper plugin to send data to it. Flipper makes this simple with built-in support.
|
|
|
|
Plugins should be treated as singleton instances as there can only be one `FlipperClient` and each `FlipperClient` can only have one instance of a certain plugin. The Flipper API makes this simple by offering a way to get the current client and query it for plugins.
|
|
|
|
Plugins are identified by the string that their identifier method returns, in this example, "MyFlipperPlugin". Note that null checks may be required as plugins may not be initialized, for example in production builds.
|
|
|
|
<Tabs defaultValue="android" values={[{label: 'Android', value: 'android'}, { label: 'iOS', value: 'ios'}, { label: 'C++', value: 'cpp'}]}>
|
|
<TabItem value="android">
|
|
|
|
```java
|
|
final FlipperClient client = AndroidFlipperClient.getInstance(context);
|
|
if (client != null) {
|
|
final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
|
|
plugin.sendData(myData);
|
|
}
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="ios">
|
|
|
|
```objective-c
|
|
FlipperClient *client = [FlipperClient sharedClient];
|
|
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
|
|
[myPlugin sendData:myData];
|
|
```
|
|
|
|
</TabItem>
|
|
<TabItem value="cpp">
|
|
|
|
```cpp
|
|
auto& client = FlipperClient::instance();
|
|
auto myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");
|
|
if (myPlugin) {
|
|
myPlugin->sendData(myData);
|
|
}
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
|
|
Here, `sendData` is an example of a method that might be implemented by the Flipper plugin.
|