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,31 @@
|
||||
/*
|
||||
* 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.sample;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.facebook.flipper.plugins.navigation.NavigationFlipperPlugin;
|
||||
import com.facebook.litho.Component;
|
||||
import com.facebook.litho.ComponentContext;
|
||||
import com.facebook.litho.LithoView;
|
||||
import com.facebook.litho.widget.Text;
|
||||
|
||||
public class DeepLinkActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
NavigationFlipperPlugin.getInstance().sendNavigationEvent("flipper://deep_link_activity/");
|
||||
|
||||
final ComponentContext context = new ComponentContext(this);
|
||||
|
||||
final Component component =
|
||||
Text.create(context).text("Welcome to the Deep Link Activity!").textSizeDip(40).build();
|
||||
|
||||
setContentView(LithoView.create(context, component));
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import android.database.DatabaseUtils;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.flipper.android.AndroidFlipperClient;
|
||||
import com.facebook.flipper.core.FlipperClient;
|
||||
import com.facebook.flipper.plugins.navigation.NavigationFlipperPlugin;
|
||||
import com.facebook.flipper.sample.network.NetworkClient;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class FlipperSampleApplication extends Application {
|
||||
Fresco.initialize(this);
|
||||
|
||||
final FlipperClient client = AndroidFlipperClient.getInstance(this);
|
||||
client.addPlugin(NavigationFlipperPlugin.getInstance());
|
||||
|
||||
final FlipperInitializer.IntializationResult initializationResult =
|
||||
FlipperInitializer.initFlipperPlugins(this, client);
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.facebook.flipper.android.AndroidFlipperClient;
|
||||
import com.facebook.flipper.core.FlipperClient;
|
||||
import com.facebook.flipper.plugins.example.ExampleFlipperPlugin;
|
||||
import com.facebook.flipper.plugins.navigation.NavigationFlipperPlugin;
|
||||
import com.facebook.litho.ComponentContext;
|
||||
import com.facebook.litho.LithoView;
|
||||
|
||||
@@ -19,6 +20,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
NavigationFlipperPlugin.getInstance().sendNavigationEvent("flipper://demo_page/");
|
||||
|
||||
final ComponentContext c = new ComponentContext(this);
|
||||
setContentView(LithoView.create(c, RootComponent.create(c).build()));
|
||||
|
||||
|
||||
@@ -62,6 +62,12 @@ public class RootComponentSpec {
|
||||
.key("5")
|
||||
.textSizeSp(20)
|
||||
.clickHandler(RootComponent.loadImage(c)))
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text("Navigate to another page")
|
||||
.key("5")
|
||||
.textSizeSp(20)
|
||||
.clickHandler(RootComponent.openAlternateActivityOne(c)))
|
||||
.child(displayImage ? FrescoImage.create(c).controller(controller) : null)
|
||||
.build();
|
||||
}
|
||||
@@ -87,6 +93,12 @@ public class RootComponentSpec {
|
||||
c.getAndroidContext().startActivity(intent);
|
||||
}
|
||||
|
||||
@OnEvent(ClickEvent.class)
|
||||
static void openAlternateActivityOne(final ComponentContext c) {
|
||||
final Intent intent = new Intent(c.getAndroidContext(), DeepLinkActivity.class);
|
||||
c.getAndroidContext().startActivity(intent);
|
||||
}
|
||||
|
||||
@OnUpdateState
|
||||
static void updateDisplayImage(StateValue<Boolean> displayImage) {
|
||||
displayImage.set(true);
|
||||
|
||||
Reference in New Issue
Block a user