Open source version of Navigation Plugin
Summary: Here I have an early version of the Navigation Plugin (Android) for Open Source. A lot of apps will be using there own Navigation framework for handling deep links. In order to keep things as simple as possible, recording navigation events is done through a single function that can be called from anywhere in the app. This will allow users to place this function in there own navigation frameworks and use there own logic with it. Seperately, I have shown how this can be used with our Android sample app. I use the built in Android intent-filters to provide a demo of how this can potentially be used, and to form the basis of the docs that I will write. Reviewed By: passy, danielbuechele Differential Revision: D16828049 fbshipit-source-id: 22765f63ca0c471689d2ec5865fdfc155b92697f
This commit is contained in:
committed by
Facebook Github Bot
parent
86f01d998f
commit
8f6740bb01
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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 androidx.annotation.Nullable;
|
||||
import com.facebook.flipper.core.FlipperConnection;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.core.FlipperPlugin;
|
||||
import com.facebook.flipper.core.FlipperReceiver;
|
||||
import com.facebook.flipper.core.FlipperResponder;
|
||||
|
||||
public class NavigationFlipperPlugin implements FlipperPlugin {
|
||||
|
||||
private FlipperConnection mConnection = null;
|
||||
|
||||
@Nullable private static NavigationFlipperPlugin instance = null;
|
||||
|
||||
private NavigationFlipperPlugin() {}
|
||||
|
||||
public void sendNavigationEvent(@Nullable String keyURI) {
|
||||
if (mConnection != null) {
|
||||
mConnection.send("nav_event", new FlipperObject.Builder().put("uri", keyURI).build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "Navigation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnect(FlipperConnection connection) throws Exception {
|
||||
mConnection = connection;
|
||||
connection.receive(
|
||||
"greet",
|
||||
new FlipperReceiver() {
|
||||
@Override
|
||||
public void onReceive(FlipperObject params, FlipperResponder responder) throws Exception {
|
||||
responder.success(new FlipperObject.Builder().put("greeting", "Hello").build());
|
||||
}
|
||||
});
|
||||
mConnection.send("nav_plugin_active", new FlipperObject.Builder().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect() throws Exception {}
|
||||
|
||||
@Override
|
||||
public boolean runInBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static NavigationFlipperPlugin getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new NavigationFlipperPlugin();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
/* @scarf-info: do not remove, more info: https://fburl.com/scarf */
|
||||
/* @scarf-generated: flipper-plugin android/Plugin.java 0bfa32e5-fb15-4705-81f8-86260a1f3f8e */
|
||||
@@ -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 = NavigationFlipperPlugin.getInstance();
|
||||
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 */
|
||||
Reference in New Issue
Block a user