Summary:
This Diff introduces an example for how to develop a React Native pure JS plugin and will be used in the docs. See the attached project as demo. The RN sources for the plugin component are:
```
import React, {useState, useEffect} from "react";
import {
StyleSheet,
View,
Text,
Button,
} from 'react-native';
import {addPlugin} from "react-native-flipper";
const initialState = {
cells: [" ", " ", " "," ", " ", " "," ", " ", " ",],
turn: ' ',
winner: ' ',
}
export default function FlipperTicTacToe() {
const [status, setStatus] = useState("Waiting for Flipper Desktop Player...")
const [gameState, setGameState] = useState(initialState);
const [connection, setConnection] = useState(null);
useEffect(() => {
addPlugin({
getId() {
return 'ReactNativeTicTacToe';
},
onConnect(connection) {
setStatus("Desktop player present");
setConnection(connection);
// listen to updates
connection.receive('SetState', (gameState, responder) => {
if (gameState.winner !== " ") {
setStatus(`Winner is ${gameState.winner}! Waiting for a new game...`);
} else {
setStatus(gameState.turn === "X" ? "Your turn...": "Awaiting desktop players turn...");
}
setGameState(gameState);
responder.success();
})
// request initial state
connection.send('GetState');
},
onDisconnect() {
setConnection(null);
setStatus("Desktop player gone...");
}
})
}, []);
return (
<View style={styles.container}>
<Text style={styles.title}>Flipper Tic-Tac-Toe</Text>
<Text>{status}</Text>
<View style={styles.board}>
{gameState.cells.map((state, idx) =>
<View
key={idx}
style={styles.cell}>
<Button
title={state}
disabled={gameState.turn !== 'X' || state !== ' '}
onPress={() => {
connection.send('XMove', { move: idx });
}}
/>
</View>
)}
</View>
</View>
)
}
// Omitted styling
```
Reviewed By: passy
Differential Revision: D19410138
fbshipit-source-id: 93266a1ef7b86dcf043a744c3563dab0c585c8fd
Flipper

Flipper (formerly Sonar) is a platform for debugging mobile apps on iOS and Android. Visualize, inspect, and control your apps from a simple desktop interface. Use Flipper as is or extend it using the plugin API.
Table of Contents
- Mobile development
- Extending Flipper
- Contributing to Flipper
- In this repo
- Getting started
- Building from Source
- iOS SDK + Sample App
- Android SDK + Sample app
- Documentation
- Contributing
- License
Mobile development
Flipper aims to be your number one companion for mobile app development on iOS and Android. Therefore, we provide a bunch of useful tools, including a log viewer, interactive layout inspector, and network inspector.
Extending Flipper
Flipper is built as a platform. In addition to using the tools already included, you can create your own plugins to visualize and debug data from your mobile apps. Flipper takes care of sending data back and forth, calling functions, and listening for events on the mobile app.
Contributing to Flipper
Both Flipper's desktop app and native mobile SDKs are open-source and MIT licensed. This enables you to see and understand how we are building plugins, and of course, join the community and help improve Flipper. We are excited to see what you will build on this platform.
In this repo
This repository includes all parts of Flipper. This includes:
- Flipper's desktop app built using Electron (
/src) - native Flipper SDKs for iOS (
/iOS) - native Flipper SDKs for Android (
/android) - Plugins:
- Logs (
/src/device-plugins/logs) - Layout inspector (
/src/plugins/layout) - Network inspector (
/src/plugins/network) - Shared Preferences/NSUserDefaults inspector (
/src/plugins/shared_preferences)
- Logs (
- website and documentation (
/website//docs)
Getting started
Please refer to our Getting Started guide to set up Flipper.
Requirements
- node >= 8
- yarn >= 1.5
- iOS developer tools (for developing iOS plugins)
- Android SDK and adb
Building from Source
Desktop
Running from source
git clone https://github.com/facebook/flipper.git
cd flipper
yarn
yarn start
NOTE: If you're on Windows, you need to use Yarn 1.5.1 until this issue is resolved.
Building standalone application
Provide either --mac, --win, --linux or any combination of them
to yarn build to build a release zip file for the given platform(s). E.g.
yarn build --mac --version $buildNumber
You can find the resulting artifact in the dist/ folder.
iOS SDK + Sample App
cd iOS/Sample
rm -f Podfile.lock
pod install --repo-update
open Sample.xcworkspace
<Run app from xcode>
You can omit --repo-update to speed up the installation, but watch out as you may be building against outdated dependencies.
Android SDK + Sample app
Start up an android emulator and run the following in the project root:
./gradlew :sample:installDebug
Documentation
Find the full documentation for this project at fbflipper.com.
Our documentation is built with Docusaurus. You can build it locally by running this:
cd website
yarn
yarn start
Contributing
See the CONTRIBUTING file for how to help out.
License
Flipper is MIT licensed, as found in the LICENSE file.
