Fixed
Status Update
Comments
le...@google.com <le...@google.com> #2
Adding Andrey and Mihai to this. What do you guys think about this? We should consider this a pretty valid use case IMO, and right now the API to do it doesn't really exist.
an...@google.com <an...@google.com> #3
I agree the proposed fix is a way to go. we should also migrate to start using it in our Popup and Dialog
po...@google.com <po...@google.com> #4
Yes, this is surely needed.
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-master-dev
commit b300d2cd6ccab823bf4dea7fea62d52f9e6ed53c
Author: Mihai Popa <popam@google.com>
Date: Tue Jun 23 16:25:50 2020
Link ViewGroup compositions to existing ones
The CL adds API to link the compositions started via
ViewGroup#setContent to the enclosing composition. This enables proper
invalidations and ambients propagation across the subcomposition border.
Based on this API, Dialogs, Popups and DropdownMenus are now able to inherit
ambients (e.g. MaterialTheme) from the wrapping composition.
Relnote: Popups, Dialogs and Menus are now inheriting the contextual MaterialTheme
Bug: 156527485
Bug: 144091550
Bug: 158804197
Bug: 158794412
Test: WrapperTest, PopupTest, DialogTest
Change-Id: Ia3665905218b4d12d7a9bd121a69a51569d82694
M ui/ui-core/api/0.1.0-dev15.txt
M ui/ui-core/api/current.txt
M ui/ui-core/api/public_plus_experimental_0.1.0-dev15.txt
M ui/ui-core/api/public_plus_experimental_current.txt
M ui/ui-core/api/restricted_0.1.0-dev15.txt
M ui/ui-core/api/restricted_current.txt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/core/PopupTest.kt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/core/test/WrapperTest.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/Popup.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/Wrapper.kt
M ui/ui-desktop/src/jvmMain/kotlin/androidx/ui/desktop/Wrapper.kt
M ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/DialogUiTest.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Dialog.kt
M ui/ui-material/src/main/java/androidx/ui/material/AlertDialog.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/ActivityWithActionBar.kt
https://android-review.googlesource.com/1347523
Branch: androidx-master-dev
commit b300d2cd6ccab823bf4dea7fea62d52f9e6ed53c
Author: Mihai Popa <popam@google.com>
Date: Tue Jun 23 16:25:50 2020
Link ViewGroup compositions to existing ones
The CL adds API to link the compositions started via
ViewGroup#setContent to the enclosing composition. This enables proper
invalidations and ambients propagation across the subcomposition border.
Based on this API, Dialogs, Popups and DropdownMenus are now able to inherit
ambients (e.g. MaterialTheme) from the wrapping composition.
Relnote: Popups, Dialogs and Menus are now inheriting the contextual MaterialTheme
Bug: 156527485
Bug: 144091550
Bug: 158804197
Bug: 158794412
Test: WrapperTest, PopupTest, DialogTest
Change-Id: Ia3665905218b4d12d7a9bd121a69a51569d82694
M ui/ui-core/api/0.1.0-dev15.txt
M ui/ui-core/api/current.txt
M ui/ui-core/api/public_plus_experimental_0.1.0-dev15.txt
M ui/ui-core/api/public_plus_experimental_current.txt
M ui/ui-core/api/restricted_0.1.0-dev15.txt
M ui/ui-core/api/restricted_current.txt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/core/PopupTest.kt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/core/test/WrapperTest.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/Popup.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/Wrapper.kt
M ui/ui-desktop/src/jvmMain/kotlin/androidx/ui/desktop/Wrapper.kt
M ui/ui-foundation/src/androidTest/java/androidx/ui/foundation/DialogUiTest.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Dialog.kt
M ui/ui-material/src/main/java/androidx/ui/material/AlertDialog.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/ActivityWithActionBar.kt
Description
I’ve got a view/composable structure like this:
And I want that innermost composable to be able to access ambients from the outer one.
The way to do this is first to call
compositionReference()
on the line commented[REF]
, and then use it to create the composition on the line above[DEREF]
.compositionReference()
is a public function, and works as expected. Compose APIs suchcompositionFor()
andsubcomposeInto()
accept aCompositionReference
parameter, but are lower-level than is convenient to use from regular view code (they require dealing withComponentNode
s). There's currently no way to pass theCompositionReference
into the child composition.The simplest way to support this would be for here .
ViewGroup.setContent
to take an optionalCompositionReference
parameter and plumb it through to the deepestcompositionFor
call. I've proven this works using reflection to access private APIsThis was initially discussed in this Slack thread .