Status Update
Comments
ma...@google.com <ma...@google.com>
so...@google.com <so...@google.com> #2
@ezio1497@gmail.com Could you please insert the code snippet that you've used?
Meanwhile I tried a few examples. If we change the layout direction by changing the locale (or setting the developer option "Force RTL layout direction"), it works. But if instead we set the layout direction via the ambient (Providers (LayoutDirectionAmbient provides LayoutDirection.Rtl) { Popup() }
), then the layout direction won't be propagated to the content of the Popup
If I understand correctly, the value of the layout direction set via ambient should have been propagated. So it seems like there is an issue with the ambient. Below is the minimum repro:
- Define a new ambient
val MyAmbient = ambientOf<Int>()
- Use it for Popup content size
Providers(MyAmbient provides 200) {
Popup(alignment = Alignment.CenterStart) {
val sizeDp = with(DensityAmbient.current) { MyAmbient.current.toDp() }
Box(Modifier.preferredSize(sizeDp).background(Color.Gray))
}
}
-
Run example and notice the result - Popup size is 200
-
Set the value of MyAmbient in ProvideCommonAmbients to 10
internal fun ProvideCommonAmbients(...) {
Providers(
...,
MyAmbient provides 10,
children = content
)
}
- Rerun using the same code snippet from step 2 and notice that the Popup size becomes 10. So even though we provided 200 on step 2, the content of the Popup still uses the one set on step 4.
Chuck, could you please take a look?
ez...@gmail.com <ez...@gmail.com> #3
Providers(
LayoutDirectionAmbient provides LayoutDirection.Rtl,
) {
AlertDialog(
onDismissRequest = {
showDialog = false
},
text = {
Text(
"هل تريد مسح كافة الطلب؟",
)
},
title = {
Text(
"مسح الطلب",
)
},
confirmButton = {
TextButton(onClick = {
viewModel.clear()
showDialog = false
}) {
Text("نعم", textAlign = TextAlign.Right)
}
},
dismissButton = {
TextButton(onClick = {
showDialog = false
}) {
Text("لا", textAlign = TextAlign.Right)
}
},
)
}
so...@google.com <so...@google.com> #4
Yeah, this is exactly an example I figured out doesn't work. Thanks!
ch...@google.com <ch...@google.com> #5
The reason we are seeing this is because calling Popup
, through its use of setContent
on the corresponding popup view, will call ProvideCommonAmbients
again. This means, from composition perspective it looks like,
ProvideCommonAmbients {
...
Provide(MyAmbient provides 10) {
...
ProvideCommonAmbients {
...
MyAmbient.current
}
}
}
The mental model is that ambients look up the composition for the first provider it finds of the MyAmbient
(we actually build the scope as we go but the model holds). If MyAmbient
is provided in ProvideCommonAmbients
as 200
you can see that MyAmbient.current
will provide 200
which is what Filip demonstrated above.
The solution for this is to not reprovide ambient values inProvideCustomAmbients
, such as MyAmbient
or RTL, that are expected to inherit across nested view or portaled content (such as what Popup
does). One solution is to make ProvideCommonAmbients
more complicated by looking up all the providers but I believe a better solution would be to add providesDefault
as a peer of provides
to create a provider that only has an effect if the value is not already provided by the parent. Then ProvideCommonAmbients
would be changed to use providesDefault
instead of the unconditional provides
.
Right now, given my current priorities, I would not be able to implement this soon. However I would be more than happy to help someone who is willing to take this on.
I am assigning to Clara for now until it is decided who should work on this.
po...@google.com <po...@google.com>
ap...@google.com <ap...@google.com> #6
Branch: androidx-master-dev
commit a3ff42b57f75f0cadca18ab65774dd22c9628238
Author: Mihai Popa <popam@google.com>
Date: Thu Oct 29 14:53:57 2020
Add provideDefault for ambient and use it for LD
Relnote: provideDefault was added as an alternative to provide for providing ambients, and it can be used to specify ambient values that will only be set when there is no ambient value already provided.
Fixes: 171024925
Test: PopupTest
Change-Id: Id663500276ad2ec3e5a5b1310a81efbf3acc0842
M compose/runtime/runtime/api/current.txt
M compose/runtime/runtime/api/public_plus_experimental_current.txt
M compose/runtime/runtime/api/restricted_current.txt
M compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Ambient.kt
M compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
M compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/window/PopupTest.kt
M compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/Ambients.kt
Description
Build: AI-202.7319.50.42.6863838, 202009251539,
AI-202.7319.50.42.6863838, JRE 11.0.8+10-b944.6842174x64 JetBrains s.r.o, OS Windows 10(amd64) v10.0 , screens 1920x1080, 1920x1080
AS: 4.2 Canary 13; Kotlin plugin: 1.4.10-release-Studio4.2-1; Android Gradle Plugin: 4.2.0-alpha13; Gradle: 6.7; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: (not found)
IMPORTANT: Please readhttps://developer.android.com/studio/report-bugs.html carefully and supply all required information.
Compose Version : 1.0.0-alpha05
I'm building an app that's all RTL. I have an Alert Dialog in it, but the text inside the dialog isn't following RTL. I tried changing the alignment of the text, wrapping the Alert Dialog inside an RTL provider, wrapping the text inside an RTL provider, but nothing works.
Is something wrong with the component? Or is tehre something I'm not doing?