Fragment sample test (#1328)

Summary:
Wanted to have a way to test fragment support in open source for https://github.com/facebook/flipper/issues/1209.

Stacked on https://github.com/facebook/flipper/issues/1327.
Pull Request resolved: https://github.com/facebook/flipper/pull/1328

Test Plan: ![Screenshot 2020-07-02 12 10 17](https://user-images.githubusercontent.com/9906/86352544-dc2ae300-bc5d-11ea-91f8-f6b06437f7bc.png)

Reviewed By: jknoxville

Differential Revision: D22356283

Pulled By: passy

fbshipit-source-id: 2ad84df0aae85634c8245e71f18b803ce8dd6ca0
This commit is contained in:
Pascal Hartig
2020-07-03 04:01:13 -07:00
committed by Facebook GitHub Bot
parent 74c9f8ea33
commit 51e7ce3566
8 changed files with 96 additions and 2 deletions

View File

@@ -47,6 +47,14 @@
<data android:scheme="flipper" android:host="layout_test_activity" />
</intent-filter>
</activity>
<activity android:name=".FragmentTestActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="flipper" android:host="fragment_test_activity" />
</intent-filter>
</activity>
<activity android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
android:exported="true"/>
<activity android:name="com.facebook.flipper.connectivitytest.ConnectionTestActivity"

View File

@@ -50,6 +50,7 @@ dependencies {
implementation deps.lithoWidget
implementation deps.lithoAnnotations
implementation deps.lithoFresco
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor deps.lithoProcessor
// Third-party

View File

@@ -0,0 +1,20 @@
/*
* 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;
public class FragmentTestActivity extends AppCompatActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NavigationFacade.sendNavigationEvent("flipper://fragment_test_activity/");
setContentView(com.facebook.flipper.sample.R.layout.fragment_test_activity);
}
}

View File

@@ -0,0 +1,27 @@
/*
* 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 android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
public class FragmentTestFragment extends Fragment {
public FragmentTestFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_test, container, false);
}
}

View File

@@ -85,10 +85,17 @@ public class RootComponentSpec {
.clickHandler(RootComponent.openAlternateLayoutTestActivity(c)))
.child(
Text.create(c)
.text("Crash this app")
.text("Navigate to fragment test page")
.key("8")
.marginDip(YogaEdge.ALL, 10)
.textSizeSp(20)
.clickHandler(RootComponent.openFragmentTestActivity(c)))
.child(
Text.create(c)
.text("Crash this app")
.key("9")
.marginDip(YogaEdge.ALL, 10)
.textSizeSp(20)
.clickHandler(RootComponent.triggerCrash(c)))
.child(
displayImage
@@ -134,6 +141,12 @@ public class RootComponentSpec {
c.getAndroidContext().startActivity(intent);
}
@OnEvent(ClickEvent.class)
static void openFragmentTestActivity(final ComponentContext c) {
final Intent intent = new Intent(c.getAndroidContext(), FragmentTestActivity.class);
c.getAndroidContext().startActivity(intent);
}
@OnEvent(ClickEvent.class)
static void triggerCrash(final ComponentContext c) {
throw new RuntimeException("Artificially triggered crash from Flipper sample app");

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FragmentTestFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/fragment_test_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.facebook.flipper.sample.FragmentTestFragment"/>
</LinearLayout>

View File

@@ -9,4 +9,5 @@
<resources>
<string name="app_name">Flipper</string>
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>