dimsuz
06/22/2023, 4:10 PMvalue class
-es seem to still have two issues wrt compose:
1. They do not transfer @Immutable
annotation to the wrapped type (unless it's Int)
2. Marking them as @Immutable
and passing them to the composable functions is still treated as though they are non-stable
Is this correct? Are there any issues which could be tracked for this apart from this one?
P. S. Why I care about this: I have a kotlin-only module and want to mark some data class
as immutable, but I can't because @Immutable
requires androidx.compose.runtime
and this is aar which can't be used in non-aar gradle modules.Albert Chang
06/22/2023, 4:26 PMAlbert Chang
06/22/2023, 4:26 PMephemient
06/22/2023, 7:15 PMdimsuz
06/22/2023, 10:00 PMUsing a value class is the same as using the wrapped type from the compiler's perspective, so the stability depends on the wrapped type.Hmm, but according to the issue I've linked this seems not to work atm.
dimsuz
06/22/2023, 10:01 PMnote that the annotation alone isn't enoughoh, that's news for me. Then it seems I won't get it to work even with Albert's suggestion to use jb-compose...
Stylianos Gakis
06/22/2023, 10:03 PMdimsuz
06/23/2023, 10:03 AMid("org.jetbrains.compose") version "1.4.0"
nothing like buildFeatures.compose
in this case (which is specific to AGP)?Stylianos Gakis
06/23/2023, 10:13 AMdimsuz
06/23/2023, 10:34 AMAndrey Kulikov
06/27/2023, 12:44 PMdimsuz
06/27/2023, 1:08 PMA
without compose compiler plugin applied, and another module B
with compose compiler applied and B
depends on `A`: will B
correctly see @Immutable
and @Stable
annotations in module A
and skip recompositions accordingly?
Or having compiler plugin applied everywhere is required?Stylianos Gakis
06/27/2023, 1:10 PMAlbert Chang
06/27/2023, 1:20 PMStylianos Gakis
06/27/2023, 1:24 PMAlbert Chang
06/27/2023, 1:30 PMStylianos Gakis
06/27/2023, 1:36 PMdimsuz
06/27/2023, 8:52 PMcompose.runtime
artifact which is used to have @Immutable
• this module has an interface MutableData
marked as @Immutable
, it has a simple impl without equals even
• In another module with compose compiler applied there's a data class ViewState(val a: Int, val b: MutableData)
And then this code
@Composable
fun Screen(state: ViewState) {
Widget(state.b)
}
@Composable
fun Widget(b: MutableData) {
Log.d("tag", "recmposition")
}
Then we change state.a
(int val) without changing b
and we observe recomposition logs only when @Immutable is not applied in the compose-less module. If annotation is there, no recompositions are happening.
So it seems compiler plugin is not strictly required in the dependent module? Or did we check something else here?Stylianos Gakis
06/27/2023, 8:59 PMdimsuz
06/27/2023, 9:02 PMTash
07/12/2023, 10:14 PM@Immutable
on `interface MutableData`:
unstable class ViewState {
stable val a: Int
unstable val b: MutableData
<runtime stability> = Unstable
}
With @Immutable
on `interface MutableData`:
stable class ViewState {
stable val a: Int
stable val b: MutableData
<runtime stability> = Stable
}
So was something fixed since the time this convo happened?
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1648226885245379?thread_ts=1648206217.729339&cid=CJLTWPH7SAlbert Chang
07/13/2023, 9:59 AMStylianos Gakis
07/13/2023, 10:15 AM