Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
id("com.google.devtools.ksp") version "1.8.10-1.0.9"
id("com.google.devtools.ksp") version "1.9.21-1.0.15"
// id("com.google.devtools.ksp") version "1.8.10-1.0.9"
}

android {
Expand Down Expand Up @@ -40,13 +41,19 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
kotlinCompilerExtensionVersion = "1.5.5"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:experimentalStrongSkipping=true",
)
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.sagar.composeperformance.module

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand All @@ -27,32 +28,42 @@ import dev.sagar.domain.ContactInfo
* 3. Enable the Compose compiler and make the data classes stable using the Stable annotation(s).
* However it will just be the dependency for the compose runtime and not for Compose-UI.
*/

//data class ContactInfo(
// val name: Int,
// val number: Int,
//)
@RequiresApi(Build.VERSION_CODES.O)
@Composable
@Destination
fun ModuleExample() {
println("ModuleExample")
var isChecked by remember {
mutableStateOf(false)
}
val contact = ContactInfo(name = 123, number = 1234567890)
// val contact = LocalTime.of(12, 12, 12, 12)
Column(
modifier = Modifier
) {
Checkbox(checked = isChecked, onCheckedChange = {
isChecked = it
})
ContactModule(contact = ContactInfo(name = "Sagar", number = 1234567890))
ContactModuleTesting(contact = contact)

}
}

// ISSUE: Composable is taking a data class which is in a seperate module. The Compose compiler
// cannot infer the stability of this class. As such it declares it as unstable.
@Composable
private fun ContactModule(contact: ContactInfo) {
fun ContactModuleTesting(contact: ContactInfo) {
Column {
Text(text = contact.name)
// Text(text = contact.name.toString())
Text(text = contact.toString())
Spacer(modifier = Modifier.height(8.dp))
Text(text = "${contact.number}")
// Text(text = "${contact.number}")
// Text(text = "${contact.number}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import com.ramcosta.composedestinations.annotation.Destination
* SOLUTION:
* 1. Make your param as "val" instead of "var
*/

val contactSimple = ContactInfo(name = "Sagar", number = 1234567890)
@Composable
@Destination
fun RuntimeStabilityExample() {
var isChecked by remember {
mutableStateOf(false)
}
val contact = ContactInfo(name = "Sagar", number = 1234567890)
Column(
modifier = Modifier
) {
Checkbox(checked = isChecked, onCheckedChange = {
isChecked = it
})
Contact(contact = contact)
Contact(contact = contactSimple)
}
}

Expand All @@ -49,7 +50,7 @@ private fun Contact(contact: ContactInfo) {
}

// ISSUE: Params are defined as "var" which means it's mutable, and can be changed at runtime.
private data class ContactInfo(
data class ContactInfo(
var name: String,
var number: Int,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ramcosta.composedestinations.annotation.Destination

val contact = ContactInfoFix(name = "Sagar", number = 1234567890)
@Composable
@Destination
fun RuntimeStabilityFix() {
var isChecked by remember {
mutableStateOf(false)
}
val contact = ContactInfoFix(name = "Sagar", number = 1234567890)
Column(
modifier = Modifier
) {
Expand All @@ -41,7 +41,7 @@ private fun Contact(contact: ContactInfoFix) {
}

// Solution: Params are defined as "val" which means it's immutable, and makes the runtime stability stable
private data class ContactInfoFix(
data class ContactInfoFix(
val name: String,
val number: Int,
)
Expand Down
16 changes: 9 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ true // Needed to make the Suppress annotation work for the plugins block
subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
if (project.findProperty("enableComposeCompilerReports") == "true") {
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
project.buildDir.absolutePath + "/compose_compiler"
)
}
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
project.buildDir.absolutePath + "/compose_compiler"
)
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
project.buildDir.absolutePath + "/compose_compiler"
)
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=$rootDir/config/compose_compiler_config.conf",
)
}
}
}
8 changes: 8 additions & 0 deletions config/compose_compiler_config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file contains classes (with possible wildcards) that the Compose Compiler will treat as stable.
// It allows us to define classes that our not part of our codebase without wrapping them in a stable class.
// For more information, check https://developer.android.com/jetpack/compose/performance/stability/fix#configuration-file
kotlin.collections.List
kotlin.collections.Set
kotlin.collections.Map
java.time.LocalTime
dev.sagar.domain.ContactInfo
2 changes: 1 addition & 1 deletion domain/src/main/java/dev/sagar/domain/ContactInfo.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.sagar.domain

data class ContactInfo(
val name: String,
val name: Int,
val number: Int,
)
10 changes: 8 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
agp = "8.3.0-alpha02"
kotlin = "1.8.10"
agp = "8.3.0"
kotlin = "1.9.20"
core-ktx = "1.9.0"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
Expand All @@ -14,6 +14,8 @@ material = "1.9.0"
kotlinx-collections-immutable = "0.3.4"
compose-viewmodel = "2.6.1"
coroutines-core = "1.7.3"
compose-lint-checks = "1.2.0"
compose-destinations = "1.9.52"

[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
Expand All @@ -37,6 +39,10 @@ kotlinx-collections-immutable = { group = "org.jetbrains.kotlinx", name = "kotli
compose-viewmodel = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "compose-viewmodel" }
coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines-core" }

compose-lint-checks = { module = "com.slack.lint.compose:compose-lint-checks", version.ref = "compose-lint-checks" }
compose-destinations-core = { module = "io.github.raamcosta.compose-destinations:compose-destinations-core", version.ref = "compose-destinations" }
compose-destinations-ksp = { module = "io.github.raamcosta.compose-destinations:compose-destinations-ksp", version.ref = "compose-destinations" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 18 18:15:27 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists