commit | fb881b992b7483f5654bc6cd8347c3d1d90fc578 | [log] [tgz] |
---|---|---|
author | Chuck Jazdzewski <[email protected]> | Fri Mar 22 16:01:20 2024 +0000 |
committer | Gerrit Code Review <[email protected]> | Fri Mar 22 16:01:20 2024 +0000 |
tree | 877f38a648e5a3a379976ec78461432110bb8b98 | |
parent | 1332d973c88502d2ac2e40489b184efc2f467bb6 [diff] | |
parent | 9d1a9217e6aff40d256c035f79490e888fe2e13a [diff] |
Merge "Fix provide single values handling providesDefault" into androidx-main
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt index d57031f..d21e787 100644 --- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt +++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
@@ -2219,7 +2219,9 @@ val providers: PersistentCompositionLocalMap val invalid: Boolean if (inserting) { - providers = parentScope.putValue(local, state) + providers = if (value.canOverride || !parentScope.contains(local)) { + parentScope.putValue(local, state) + } else { parentScope } invalid = false writerHasAProvider = true } else {
diff --git a/compose/runtime/runtime/src/nonEmulatorCommonTest/kotlin/androidx/compose/runtime/CompositionLocalTests.kt b/compose/runtime/runtime/src/nonEmulatorCommonTest/kotlin/androidx/compose/runtime/CompositionLocalTests.kt index 4144ccd..ddfcc02 100644 --- a/compose/runtime/runtime/src/nonEmulatorCommonTest/kotlin/androidx/compose/runtime/CompositionLocalTests.kt +++ b/compose/runtime/runtime/src/nonEmulatorCommonTest/kotlin/androidx/compose/runtime/CompositionLocalTests.kt
@@ -702,6 +702,18 @@ revalidate() } + + @Test // Regression test for: b/330036209 + fun testSingleProvideDefaultValue() = compositionTest { + val local = compositionLocalOf { 0 } + compose { + CompositionLocalProvider(local provides 1) { + CompositionLocalProvider(local providesDefault 2) { + assertEquals(1, local.current) + } + } + } + } } val cacheLocal = staticCompositionLocalOf { "Unset" }