diff --git a/android/src/test/java/com/facebook/flipper/plugins/navigation/NavigationFlipperPluginTest.java b/android/src/test/java/com/facebook/flipper/plugins/navigation/NavigationFlipperPluginTest.java new file mode 100644 index 000000000..d3da2a0c4 --- /dev/null +++ b/android/src/test/java/com/facebook/flipper/plugins/navigation/NavigationFlipperPluginTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ +package com.facebook.flipper.plugins.navigation; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; + +import com.facebook.flipper.core.FlipperObject; +import com.facebook.flipper.testing.FlipperConnectionMock; +import com.facebook.flipper.testing.FlipperResponderMock; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class NavigationFlipperPluginTest { + @Test + public void greetingTest() throws Exception { + final NavigationFlipperPlugin plugin = new NavigationFlipperPlugin(); + final FlipperConnectionMock connection = new FlipperConnectionMock(); + final FlipperResponderMock responder = new FlipperResponderMock(); + + plugin.onConnect(connection); + connection.receivers.get("greet").onReceive(null, responder); + + assertThat( + responder.successes, hasItem(new FlipperObject.Builder().put("greeting", "Hello").build())); + } +} + +/* @scarf-info: do not remove, more info: https://fburl.com/scarf */ +/* @scarf-generated: flipper-plugin android/test/PluginTest.java 0bfa32e5-fb15-4705-81f8-86260a1f3f8e */ diff --git a/src/plugins/navigation/index.js b/src/plugins/navigation/index.js new file mode 100644 index 000000000..1e67800b5 --- /dev/null +++ b/src/plugins/navigation/index.js @@ -0,0 +1,58 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + * @flow strict-local + */ + +import {FlipperPlugin, FlexColumn} from 'flipper'; + +type State = {||}; + +type Data = {||}; + +type PersistedState = {| + data: Array, +|}; + +export default class extends FlipperPlugin { + static title = 'Navigation'; + static id = 'Navigation'; + static icon = 'directions'; + static keyboardActions = ['clear']; + + static defaultPersistedState: PersistedState = { + data: [], + }; + + static persistedStateReducer = ( + persistedState: PersistedState, + method: string, + data: Data, + ): $Shape => { + return { + ...persistedState, + data: persistedState.data.concat([data]), + }; + }; + + onKeyboardAction = (action: string) => { + if (action === 'clear') { + this.props.setPersistedState({data: []}); + } + }; + + render() { + return ( + + {this.props.persistedState.data.map((d, i) => ( +
{JSON.stringify(d)}
+ ))} +
+ ); + } +} + +/* @scarf-info: do not remove, more info: https://fburl.com/scarf */ +/* @scarf-generated: flipper-plugin index.js.template 0bfa32e5-fb15-4705-81f8-86260a1f3f8e */ diff --git a/src/plugins/navigation/package.json b/src/plugins/navigation/package.json new file mode 100644 index 000000000..4205bf89f --- /dev/null +++ b/src/plugins/navigation/package.json @@ -0,0 +1,12 @@ +{ + "name": "flipper-plugin-navigation", + "version": "0.0.1", + "main": "index.js", + "license": "MIT", + "gatekeeper": "flipper_navigation", + "title": "Navigation", + "icon": "directions", + "bugs": { + "email": "beneloca@fb.com" + } + }