Add jetpack compose to sample app

Summary: Add an entry to the sample app to showcase Jetpack compose support. Note that you need to enable View Attribute Debugging in the Android Debug settings for this to work.

Reviewed By: lblasa

Differential Revision: D46933645

fbshipit-source-id: fbe2ddd50ef0e7917ef873959db5b3f35b833cf0
This commit is contained in:
Pascal Hartig
2023-06-23 14:42:14 -07:00
committed by Facebook GitHub Bot
parent ad25c2468d
commit 820cf6a75e
5 changed files with 80 additions and 6 deletions

View File

@@ -0,0 +1,30 @@
package com.facebook.flipper.sample
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
@Composable
fun MessageCard(name: String) {
Row(modifier = Modifier.padding(all = 8.dp)) { Text(text = "Hello $name!") }
}
@Preview
@Composable
fun PreviewMessageCard() {
MessageCard("Android")
}
class JetpackComposeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { MessageCard("Flipper") }
}
}

View File

@@ -116,10 +116,17 @@ public class RootComponentSpec {
.clickHandler(RootComponent.openIncrementActivity(c)))
.child(
Text.create(c)
.text("Crash this app")
.text("Navigate to Jetpack Compose activity")
.key("12")
.marginDip(YogaEdge.ALL, 10)
.textSizeSp(20)
.clickHandler(RootComponent.openJetpackComposeActivity(c)))
.child(
Text.create(c)
.text("Crash this app")
.key("13")
.marginDip(YogaEdge.ALL, 10)
.textSizeSp(20)
.clickHandler(RootComponent.triggerCrash(c)))
.child(
FrescoImage.create(c)
@@ -203,4 +210,10 @@ public class RootComponentSpec {
final Intent intent = new Intent(c.getAndroidContext(), ButtonsActivity.class);
c.getAndroidContext().startActivity(intent);
}
@OnEvent(ClickEvent.class)
static void openJetpackComposeActivity(final ComponentContext c) {
final Intent intent = new Intent(c.getAndroidContext(), JetpackComposeActivity.class);
c.getAndroidContext().startActivity(intent);
}
}