Skip to content

Commit

Permalink
feat: ensure compose and models are stable for Compose Compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Jul 15, 2024
1 parent 66d7350 commit 6a6345b
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 87 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ If you are interested to create your own UI, you can use the component `OpenFeed
`Composable` takes OpenFeedback Model UI in input and you can use `OpenFeedbackViewModel` in the
viewmodel artifact to get the data from the Firebase host.

## Metrics

If you change Compose contracts or model ui, you can run the following command to check if
Composable or models are still stable:

```shell
./gradlew assembleRelease -PcomposeCompilerReports=true -PcomposeCompilerMetrics=true
```

Then, you can check the `build/compose_compiler` folder where we are using Compose UI to check
metrics.

## Installation

The SDK is available on mavenCentral:
Expand Down
18 changes: 13 additions & 5 deletions build-logic/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.android.build.api.dsl.CommonExtension
import com.gradleup.librarian.gradle.*
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Expand All @@ -17,9 +16,19 @@ private fun Project.configureAndroid(namespace: String) {
}
}

private fun Project.configureKotlin() {
private fun Project.configureKotlin(composeMetrics: Boolean) {
tasks.withType(KotlinCompile::class.java) {
it.kotlinOptions.freeCompilerArgs += "-Xexpect-actual-classes"
if (composeMetrics) {
if (project.findProperty("composeCompilerReports") == "true") {
it.kotlinOptions.freeCompilerArgs += "-P"
it.kotlinOptions.freeCompilerArgs += "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${project.buildDir.absolutePath}/compose_compiler"
}
if (project.findProperty("composeCompilerMetrics") == "true") {
it.kotlinOptions.freeCompilerArgs += "-P"
it.kotlinOptions.freeCompilerArgs += "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=${project.buildDir.absolutePath}/compose_compiler"
}
}
}
}

Expand Down Expand Up @@ -48,17 +57,16 @@ fun Project.library(
configureAndroid(namespace = namespace)
configureKMP()

configureKotlin()
configureKotlin(compose)

kotlin(kotlinMultiplatformExtension)

librarianModule(publish)
}


fun Project.androidApp(
namespace: String,
) {
configureAndroid(namespace = namespace)
configureKotlin()
configureKotlin(composeMetrics = true)
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jetbrains-compose = "1.6.11"
jetbrains-kotlin = "2.0.0"
jetbrains-kotlin-coroutines = "1.8.1"
jetbrains-kotlinx-datetime = "0.6.0"
jetbrains-kotlinx-collections-immutable = "0.3.7"
jetbrains-kotlinx-serialization = "1.7.0"
jetbrains-kotlinx-binary = "0.15.0-Beta.3"
touchlab-kermit = "2.0.4"
Expand All @@ -31,6 +32,7 @@ jetbrains-kotlin-serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-
jetbrains-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "jetbrains-kotlin" }
jetbrains-kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "jetbrains-kotlin-coroutines" }
jetbrains-kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "jetbrains-kotlinx-datetime" }
jetbrains-kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "jetbrains-kotlinx-collections-immutable" }
jetbrains-kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "jetbrains-kotlinx-serialization" }
jetbrains-kotlinx-binary-compatibility-validator = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "jetbrains-kotlinx-binary" }

Expand Down
3 changes: 1 addition & 2 deletions openfeedback-m3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.plugin.serialization")
id("org.jetbrains.compose")
id("org.jetbrains.kotlin.plugin.compose")
}

library(
namespace = "io.openfeedback.m3",
compose = true,
publish = true,
) { kotlinMultiplatformExtension ->
kotlinMultiplatformExtension.sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import io.openfeedback.ui.models.UIComment
import io.openfeedback.ui.models.UIDot
import kotlinx.collections.immutable.persistentListOf

@Preview
@Composable
private fun CommentItemsPreview() {
MaterialTheme {
CommentItems(
comments = listOf(
comments = persistentListOf(
UIComment(
id = "",
message = "Nice comment",
createdAt = "08 August 2023",
upVotes = 8,
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true,
fromUser = false
),
Expand All @@ -26,7 +27,7 @@ private fun CommentItemsPreview() {
message = "Another comment",
createdAt = "08 August 2023",
upVotes = 0,
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true,
fromUser = false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import io.openfeedback.ui.models.UIComment
import io.openfeedback.ui.models.UIDot
import kotlinx.collections.immutable.persistentListOf

@Preview
@Composable
Expand All @@ -16,7 +17,7 @@ private fun CommentPreview() {
message = "Super talk and great speakers!",
createdAt = "08 August 2023",
upVotes = 8,
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true,
fromUser = false
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.openfeedback.ui.models.UIComment
import io.openfeedback.ui.models.UIDot
import io.openfeedback.ui.models.UISessionFeedback
import io.openfeedback.ui.models.UIVoteItem
import kotlinx.collections.immutable.persistentListOf

@OptIn(ExperimentalMaterial3Api::class)
@Preview
Expand All @@ -21,13 +22,13 @@ private fun OpenFeedbackLayoutPreview() {
MaterialTheme {
OpenFeedbackLayout(
sessionFeedback = UISessionFeedback(
comments = listOf(
comments = persistentListOf(
UIComment(
id = "",
message = "Nice comment",
createdAt = "08 August 2023",
upVotes = 8,
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true,
fromUser = false
),
Expand All @@ -36,26 +37,26 @@ private fun OpenFeedbackLayoutPreview() {
message = "Another one",
createdAt = "08 August 2023",
upVotes = 0,
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true,
fromUser = false
)
),
voteItems = listOf(
voteItems = persistentListOf(
UIVoteItem(
id = "",
text = "Fun",
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true
),
UIVoteItem(
id = "",
text = "Fun",
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true
)
),
colors = emptyList()
colors = persistentListOf()
),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.openfeedback.ui.models.UIDot
import io.openfeedback.ui.models.UIVoteItem
import kotlinx.collections.immutable.persistentListOf

@OptIn(ExperimentalMaterial3Api::class)
@Preview
Expand All @@ -19,7 +20,7 @@ private fun VoteCardPreview() {
voteModel = UIVoteItem(
id = "",
text = "Fun",
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true
),
onClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.openfeedback.ui.models.UIDot
import io.openfeedback.ui.models.UIVoteItem
import kotlinx.collections.immutable.persistentListOf

@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
private fun VoteItemsPreview() {
MaterialTheme {
VoteItems(
voteItems = listOf(
voteItems = persistentListOf(
UIVoteItem(
id = "",
text = "Fun",
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true
),
UIVoteItem(
id = "",
text = "Fun",
dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
dots = persistentListOf(UIDot(x = .5f, y = .5f, color = "FF00CC")),
votedByUser = true
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.openfeedback.resources.LocalStrings
import io.openfeedback.ui.models.UIComment
import kotlinx.collections.immutable.ImmutableList

@Composable
internal fun CommentItems(
comments: List<UIComment>,
comments: ImmutableList<UIComment>,
modifier: Modifier = Modifier,
verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
commentInput: @Composable ColumnScope.() -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.openfeedback.ui.models.UIVoteItem
import kotlinx.collections.immutable.ImmutableList

@ExperimentalMaterial3Api
@Composable
internal fun VoteItems(
voteItems: List<UIVoteItem>,
voteItems: ImmutableList<UIVoteItem>,
modifier: Modifier = Modifier,
columnCount: Int = 2,
horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(8.dp),
Expand Down
38 changes: 19 additions & 19 deletions openfeedback-ui-models/api/openfeedback-ui-models.api
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
public final class io/openfeedback/ui/models/UIComment {
public static final field $stable I
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/util/List;ZZ)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlinx/collections/immutable/ImmutableList;ZZ)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()I
public final fun component5 ()Ljava/util/List;
public final fun component5 ()Lkotlinx/collections/immutable/ImmutableList;
public final fun component6 ()Z
public final fun component7 ()Z
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/util/List;ZZ)Lio/openfeedback/ui/models/UIComment;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UIComment;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/util/List;ZZILjava/lang/Object;)Lio/openfeedback/ui/models/UIComment;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlinx/collections/immutable/ImmutableList;ZZ)Lio/openfeedback/ui/models/UIComment;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UIComment;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILkotlinx/collections/immutable/ImmutableList;ZZILjava/lang/Object;)Lio/openfeedback/ui/models/UIComment;
public fun equals (Ljava/lang/Object;)Z
public final fun getCreatedAt ()Ljava/lang/String;
public final fun getDots ()Ljava/util/List;
public final fun getDots ()Lkotlinx/collections/immutable/ImmutableList;
public final fun getFromUser ()Z
public final fun getId ()Ljava/lang/String;
public final fun getMessage ()Ljava/lang/String;
Expand Down Expand Up @@ -40,31 +40,31 @@ public final class io/openfeedback/ui/models/UIDot {

public final class io/openfeedback/ui/models/UISessionFeedback {
public static final field $stable I
public fun <init> (Ljava/util/List;Ljava/util/List;Ljava/util/List;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ljava/util/List;
public final fun copy (Ljava/util/List;Ljava/util/List;Ljava/util/List;)Lio/openfeedback/ui/models/UISessionFeedback;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UISessionFeedback;Ljava/util/List;Ljava/util/List;Ljava/util/List;ILjava/lang/Object;)Lio/openfeedback/ui/models/UISessionFeedback;
public fun <init> (Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;)V
public final fun component1 ()Lkotlinx/collections/immutable/ImmutableList;
public final fun component2 ()Lkotlinx/collections/immutable/ImmutableList;
public final fun component3 ()Lkotlinx/collections/immutable/ImmutableList;
public final fun copy (Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;)Lio/openfeedback/ui/models/UISessionFeedback;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UISessionFeedback;Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;Lkotlinx/collections/immutable/ImmutableList;ILjava/lang/Object;)Lio/openfeedback/ui/models/UISessionFeedback;
public fun equals (Ljava/lang/Object;)Z
public final fun getColors ()Ljava/util/List;
public final fun getComments ()Ljava/util/List;
public final fun getVoteItems ()Ljava/util/List;
public final fun getColors ()Lkotlinx/collections/immutable/ImmutableList;
public final fun getComments ()Lkotlinx/collections/immutable/ImmutableList;
public final fun getVoteItems ()Lkotlinx/collections/immutable/ImmutableList;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class io/openfeedback/ui/models/UIVoteItem {
public static final field $stable I
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Lkotlinx/collections/immutable/ImmutableList;Z)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/util/List;
public final fun component3 ()Lkotlinx/collections/immutable/ImmutableList;
public final fun component4 ()Z
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)Lio/openfeedback/ui/models/UIVoteItem;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UIVoteItem;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZILjava/lang/Object;)Lio/openfeedback/ui/models/UIVoteItem;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Lkotlinx/collections/immutable/ImmutableList;Z)Lio/openfeedback/ui/models/UIVoteItem;
public static synthetic fun copy$default (Lio/openfeedback/ui/models/UIVoteItem;Ljava/lang/String;Ljava/lang/String;Lkotlinx/collections/immutable/ImmutableList;ZILjava/lang/Object;)Lio/openfeedback/ui/models/UIVoteItem;
public fun equals (Ljava/lang/Object;)Z
public final fun getDots ()Ljava/util/List;
public final fun getDots ()Lkotlinx/collections/immutable/ImmutableList;
public final fun getId ()Ljava/lang/String;
public final fun getText ()Ljava/lang/String;
public final fun getVotedByUser ()Z
Expand Down
Loading

0 comments on commit 6a6345b

Please sign in to comment.