Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit fb6db65f6a6ebe8cb764e640b2f4723a25151bde
Author: Chuck Jazdzewski <chuckj@google.com>
Date: Mon Nov 25 08:30:51 2019
Change ambients to a more efficient implementation
Removed Ambient.Provide/Ambient.Consume and ambient() in favor of
Provides() and Ambient<T>.current.
Uses a hash lookup instead of linear scan to determine
the value of an ambient.
Uses a State<T> backed implementation instead to track
reads of ambients instead of custom tracking and invalidation.
Introduces a static ambient that is very cheap to read but very
expensive to change to be used for ambients that rarely or never
change.
Relnote: "Breaking changes to the ambients API. See log and Ambient<T> documentation for details"
BREAKING CHANGES:
- Ambient keys are now created with `ambientOf()` or
`staticAmbientOf()` instead of `Ambient.of()`.
`Ambient.of()` has been removed.
- Consume ambients with `Ambient<T>.current` instead of
using `ambient()`. `ambient()` still works but is
deprecated.
- Ambient<T>.Consume was previous discouraged and is now
removed.
- Ambients are now provided using `Provides()` instead
of `Ambient<T>.Provide`. `Ambient<T>.Provide` has been
removed.
Fixes: 144283395, 143769776
Test: Existing tests pass. New tests added.
Change-Id: I4c7eea45f2b7bf41f8a8ba75fd667c06010469a9
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/ComposeCallLoweringTests.kt
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/ComposeCallResolverTests.kt
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/FcsCodegenTests.kt
M compose/compose-runtime/api/0.1.0-dev04.txt
M compose/compose-runtime/api/api_lint.ignore
M compose/compose-runtime/api/current.txt
M compose/compose-runtime/api/public_plus_experimental_0.1.0-dev04.txt
M compose/compose-runtime/api/public_plus_experimental_current.txt
M compose/compose-runtime/api/restricted_0.1.0-dev04.txt
M compose/compose-runtime/api/restricted_current.txt
M compose/compose-runtime/build.gradle
M compose/compose-runtime/integration-tests/samples/src/main/java/androidx/compose/samples/AmbientSamples.kt
A compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/AmbientTests.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/ComposerExtensions.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/EffectsTests.kt
M compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualJvm.kt
M compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ViewComposer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Ambient.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Composer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionReference.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Effects.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Expect.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/FrameManager.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ObserverMap.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SlotTable.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Stack.kt
A compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ValueHolders.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ViewComposerCommon.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/frames/Frames.kt
M compose/compose-runtime/src/commonTest/kotlin/androidx/compose/SlotTableTests.kt
M compose/compose-runtime/src/commonTest/kotlin/androidx/compose/frames/FramesTests.kt
M ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/ModelObserverBenchmark.kt
M ui/integration-tests/test/src/androidTest/java/androidx/ui/integration/test/ColorPaletteTest.kt
M ui/ui-android-view/integration-tests/android-view-demos/src/main/java/androidx/ui/androidview/demos/ViewInCompose.kt
M ui/ui-animation-core/api/api_lint.ignore
M ui/ui-animation/api/0.1.0-dev04.txt
M ui/ui-animation/api/current.txt
M ui/ui-animation/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-animation/api/public_plus_experimental_current.txt
M ui/ui-animation/api/restricted_0.1.0-dev04.txt
M ui/ui-animation/api/restricted_current.txt
M ui/ui-animation/integration-tests/animation-demos/src/main/java/androidx/ui/animation/demos/AnimatableSeekBar.kt
M ui/ui-animation/src/main/java/androidx/ui/animation/AnimatedValueEffects.kt
M ui/ui-animation/src/main/java/androidx/ui/animation/Transition.kt
M ui/ui-core/api/api_lint.ignore
M ui/ui-foundation/src/main/java/androidx/ui/foundation/ContentColor.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/DarkTheme.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Dialog.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/animation/FlingConfig.kt
M ui/ui-framework/api/0.1.0-dev04.txt
M ui/ui-framework/api/current.txt
M ui/ui-framework/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-framework/api/public_plus_experimental_current.txt
M ui/ui-framework/api/restricted_0.1.0-dev04.txt
M ui/ui-framework/api/restricted_current.txt
M ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/autofill/ExplicitAutofillTypesActivity.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldFocusTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeEditorModelTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeFullEditorModelTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeStringTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/ColorResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/PrimitiveResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/ResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/StringResourcesTest.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Draw.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Layout.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Popup.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
M ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Wrapper.kt
M ui/ui-framework/src/main/java/androidx/ui/core/gesture/DoubleTapGestureDetector.kt
M ui/ui-framework/src/main/java/androidx/ui/core/gesture/LongPressGestureDetector.kt
M ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt
M ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionRegistrar.kt
M ui/ui-framework/src/main/java/androidx/ui/res/ColorResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/ImageResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/PrimitiveResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/Resources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/StringResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/VectorResources.kt
M ui/ui-framework/src/main/java/androidx/ui/tooling/InspectionMode.kt
A ui/ui-geometry/api/api_lint.ignore
M ui/ui-material/api/0.1.0-dev04.txt
M ui/ui-material/api/current.txt
M ui/ui-material/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-material/api/public_plus_experimental_current.txt
M ui/ui-material/api/restricted_0.1.0-dev04.txt
M ui/ui-material/api/restricted_current.txt
M ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt
M ui/ui-material/src/main/java/androidx/ui/material/Color.kt
M ui/ui-material/src/main/java/androidx/ui/material/Emphasis.kt
M ui/ui-material/src/main/java/androidx/ui/material/MaterialTheme.kt
M ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt
M ui/ui-material/src/main/java/androidx/ui/material/Shape.kt
M ui/ui-material/src/main/java/androidx/ui/material/Typography.kt
M ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt
M ui/ui-material/src/main/java/androidx/ui/material/ripple/RippleTheme.kt
M ui/ui-platform/api/restricted_0.1.0-dev04.txt
M ui/ui-platform/api/restricted_current.txt
M ui/ui-platform/src/main/java/androidx/ui/core/ModelObserver.kt
M ui/ui-test/api/api_lint.ignore
M ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/ComposeInputFieldFocusTransition.kt
M ui/ui-tooling/src/main/java/androidx/ui/tooling/Inspectable.kt
M ui/ui-tooling/src/main/java/androidx/ui/tooling/preview/ComposeViewAdapter.kt
https://android-review.googlesource.com/1206889
Branch: androidx-master-dev
commit fb6db65f6a6ebe8cb764e640b2f4723a25151bde
Author: Chuck Jazdzewski <chuckj@google.com>
Date: Mon Nov 25 08:30:51 2019
Change ambients to a more efficient implementation
Removed Ambient.Provide/Ambient.Consume and ambient() in favor of
Provides() and Ambient<T>.current.
Uses a hash lookup instead of linear scan to determine
the value of an ambient.
Uses a State<T> backed implementation instead to track
reads of ambients instead of custom tracking and invalidation.
Introduces a static ambient that is very cheap to read but very
expensive to change to be used for ambients that rarely or never
change.
Relnote: "Breaking changes to the ambients API. See log and Ambient<T> documentation for details"
BREAKING CHANGES:
- Ambient keys are now created with `ambientOf()` or
`staticAmbientOf()` instead of `Ambient.of()`.
`Ambient.of()` has been removed.
- Consume ambients with `Ambient<T>.current` instead of
using `ambient()`. `ambient()` still works but is
deprecated.
- Ambient<T>.Consume was previous discouraged and is now
removed.
- Ambients are now provided using `Provides()` instead
of `Ambient<T>.Provide`. `Ambient<T>.Provide` has been
removed.
Fixes: 144283395, 143769776
Test: Existing tests pass. New tests added.
Change-Id: I4c7eea45f2b7bf41f8a8ba75fd667c06010469a9
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/ComposeCallLoweringTests.kt
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/ComposeCallResolverTests.kt
M compose/compose-compiler-hosted/integration-tests/src/test/java/androidx/compose/plugins/kotlin/FcsCodegenTests.kt
M compose/compose-runtime/api/0.1.0-dev04.txt
M compose/compose-runtime/api/api_lint.ignore
M compose/compose-runtime/api/current.txt
M compose/compose-runtime/api/public_plus_experimental_0.1.0-dev04.txt
M compose/compose-runtime/api/public_plus_experimental_current.txt
M compose/compose-runtime/api/restricted_0.1.0-dev04.txt
M compose/compose-runtime/api/restricted_current.txt
M compose/compose-runtime/build.gradle
M compose/compose-runtime/integration-tests/samples/src/main/java/androidx/compose/samples/AmbientSamples.kt
A compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/AmbientTests.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/ComposerExtensions.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/EffectsTests.kt
M compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ActualJvm.kt
M compose/compose-runtime/src/androidMain/kotlin/androidx/compose/ViewComposer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Ambient.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Composer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/CompositionReference.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Effects.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Expect.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/FrameManager.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ObserverMap.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Recomposer.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/SlotTable.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/Stack.kt
A compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ValueHolders.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/ViewComposerCommon.kt
M compose/compose-runtime/src/commonMain/kotlin/androidx/compose/frames/Frames.kt
M compose/compose-runtime/src/commonTest/kotlin/androidx/compose/SlotTableTests.kt
M compose/compose-runtime/src/commonTest/kotlin/androidx/compose/frames/FramesTests.kt
M ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/ModelObserverBenchmark.kt
M ui/integration-tests/test/src/androidTest/java/androidx/ui/integration/test/ColorPaletteTest.kt
M ui/ui-android-view/integration-tests/android-view-demos/src/main/java/androidx/ui/androidview/demos/ViewInCompose.kt
M ui/ui-animation-core/api/api_lint.ignore
M ui/ui-animation/api/0.1.0-dev04.txt
M ui/ui-animation/api/current.txt
M ui/ui-animation/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-animation/api/public_plus_experimental_current.txt
M ui/ui-animation/api/restricted_0.1.0-dev04.txt
M ui/ui-animation/api/restricted_current.txt
M ui/ui-animation/integration-tests/animation-demos/src/main/java/androidx/ui/animation/demos/AnimatableSeekBar.kt
M ui/ui-animation/src/main/java/androidx/ui/animation/AnimatedValueEffects.kt
M ui/ui-animation/src/main/java/androidx/ui/animation/Transition.kt
M ui/ui-core/api/api_lint.ignore
M ui/ui-foundation/src/main/java/androidx/ui/foundation/ContentColor.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/DarkTheme.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Dialog.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/animation/FlingConfig.kt
M ui/ui-framework/api/0.1.0-dev04.txt
M ui/ui-framework/api/current.txt
M ui/ui-framework/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-framework/api/public_plus_experimental_current.txt
M ui/ui-framework/api/restricted_0.1.0-dev04.txt
M ui/ui-framework/api/restricted_current.txt
M ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/autofill/ExplicitAutofillTypesActivity.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldFocusTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeEditorModelTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeFullEditorModelTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldOnValueChangeStringTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/TextFieldTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/ColorResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/PrimitiveResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/ResourcesTest.kt
M ui/ui-framework/src/androidTest/java/androidx/ui/res/StringResourcesTest.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Draw.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Layout.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Popup.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Text.kt
M ui/ui-framework/src/main/java/androidx/ui/core/TextField.kt
M ui/ui-framework/src/main/java/androidx/ui/core/Wrapper.kt
M ui/ui-framework/src/main/java/androidx/ui/core/gesture/DoubleTapGestureDetector.kt
M ui/ui-framework/src/main/java/androidx/ui/core/gesture/LongPressGestureDetector.kt
M ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt
M ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionRegistrar.kt
M ui/ui-framework/src/main/java/androidx/ui/res/ColorResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/ImageResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/PrimitiveResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/Resources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/StringResources.kt
M ui/ui-framework/src/main/java/androidx/ui/res/VectorResources.kt
M ui/ui-framework/src/main/java/androidx/ui/tooling/InspectionMode.kt
A ui/ui-geometry/api/api_lint.ignore
M ui/ui-material/api/0.1.0-dev04.txt
M ui/ui-material/api/current.txt
M ui/ui-material/api/public_plus_experimental_0.1.0-dev04.txt
M ui/ui-material/api/public_plus_experimental_current.txt
M ui/ui-material/api/restricted_0.1.0-dev04.txt
M ui/ui-material/api/restricted_current.txt
M ui/ui-material/src/androidTest/java/androidx/ui/material/RippleEffectTest.kt
M ui/ui-material/src/main/java/androidx/ui/material/Color.kt
M ui/ui-material/src/main/java/androidx/ui/material/Emphasis.kt
M ui/ui-material/src/main/java/androidx/ui/material/MaterialTheme.kt
M ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt
M ui/ui-material/src/main/java/androidx/ui/material/Shape.kt
M ui/ui-material/src/main/java/androidx/ui/material/Typography.kt
M ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt
M ui/ui-material/src/main/java/androidx/ui/material/ripple/RippleTheme.kt
M ui/ui-platform/api/restricted_0.1.0-dev04.txt
M ui/ui-platform/api/restricted_current.txt
M ui/ui-platform/src/main/java/androidx/ui/core/ModelObserver.kt
M ui/ui-test/api/api_lint.ignore
M ui/ui-text/integration-tests/text-demos/src/main/java/androidx/ui/text/demos/ComposeInputFieldFocusTransition.kt
M ui/ui-tooling/src/main/java/androidx/ui/tooling/Inspectable.kt
M ui/ui-tooling/src/main/java/androidx/ui/tooling/preview/ComposeViewAdapter.kt
Description
@Model
class MyTheme(var primaryColor: Color)
...
val colors = MaterialColors(primary = myTheme.primaryColor)
MaterialTheme(colors) {
}
If 'MaterialTheme' internally uses an ambient, changing myTheme.primaryColor will synchronously cause the ambient value to change and update its consumers. However, if MaterialTheme actually has a @Model class that gets mutated, then this will result in another recomposition for anything consuming that @Model class.
One proposed solution could be knowing that the @Model class is mutated above the scope where it is being consumed, so in the same recomposition pass we can invalidate and recompose anything consuming it.