theapache64
01/31/2023, 7:05 AMcomposed
here, and I’ve few questions 🧵fullyQualifiedName
?
2. Can you provide a proper usecase for this? The one that’s added in the doc looks copied from the old composed
functionStylianos Gakis
01/31/2023, 10:08 AMscope.invalidate()
is called. Maybe without the full name qualifier it wouldn’t do that?Ale Stamato
01/31/2023, 12:59 PMModifier.Node
is a higher-performance alternative to Modifier.composed
Adam Powell
01/31/2023, 3:01 PMModifier.Node
instead of thisStylianos Gakis
01/31/2023, 3:05 PM@Test
fun recomposingKeyedComposedModifierSkips() = runBlocking {
// Manually invalidate the composition instead of using mutableStateOf
// Snapshot-based recomposition requires explicit snapshot commits/global write observers.
lateinit var scope: RecomposeScope
val frameClock = TestFrameClock()
withContext(frameClock) {
withRunningRecomposer { recomposer ->
var composeCount = 0
var childComposeCount = 0
// Use the same lambda instance; the capture used here is unstable
// and would prevent skipping.
val increment: (Modifier) -> Unit = { childComposeCount++ }
// <-- change, removed key as it was unused
compose(recomposer) {
scope = currentRecomposeScope
SideEffect { composeCount++ }
ModifiedComposable(Modifier.composed { Modifier }, increment) // <-- change
}
assertEquals("initial compositions", 1, composeCount)
assertEquals("initial child compositions", 1, childComposeCount)
scope.invalidate()
frameClock.frame(0L)
assertEquals("recomposed compositions", 2, composeCount)
assertEquals("recomposed child compositions", 2, childComposeCount) // <-- change
}
}
}
Changes are that I used the old Modifier.composed without the qualified name + key
And then the assertion now checks that childComposeCount is 2, not 1 like it was before.
Meaning that “recomposed child compositions” also increments to 2, showing the non-skippability of the old composed modifier.
I would definitely like to see some concrete examples in the docs though as theapache mentioned