Status Update
Comments
si...@google.com <si...@google.com>
si...@google.com <si...@google.com> #2
It is expected that BackHandler
crashes in cases where no LocalOnBackPressedDispatcherOwner
Given that LocalOnBackPressedDispatcherOwner.current
is nullable, you can certainly wrap your call to BackHandler
in a null check if you'd like to specifically disable that functionality when in @Preview
. Of course, you could just provide your own OnBackPressedDispatcherOwner
by constructing an OnBackPressedDispatcher
instance yourself as part of your @Preview
.
Andrey - any thoughts on whether we should have @Preview
automatically create and set a LocalOnBackPressedDispatcherOwner
as we do for LocalViewModelStoreOwner
ma...@google.com <ma...@google.com> #3
Note that in previews we do not really support ViewModels in reality. We provide a fake ViewModelStoreOwner, but this implementation just crashes when you try to create a ViewModel. It was a Sergey's idea as usually ViewModels are doing some network/database requests and we don't really support it in the preview mode.
si...@google.com <si...@google.com> #4
Branch: androidx-main
commit 026203513c5a704abeaa34595e7a7e7ab06876f7
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:47:14 2021
Add an ActivityResultRegistry to Compose Previews
An ActivityResultRegistry is provided by default
by ComponentActivity, but using APIs that depend on
it, like rememberLauncherForActivityResult() would
crash in @Preview. By adding a fake implementation,
developers can preview those Composables.
For cases where they call `launch()` (i.e., the
`startActivityForResult()` equivalent), the fake
throws an IllegalStateException to indicate that
actually starting an activity / permission request
in Preview is not supported.
Relnote: "Compose `@Preview` now provides a
`LocalActivityResultRegistryOwner` that allows you
to preview Composables that use APIs like
`rememberLauncherForActivityResult()` that depend
on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ib13d12f085065adb89cfb731179b9295029e06e9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
ex...@gmail.com <ex...@gmail.com> #5
Branch: androidx-main
commit 622947a991ba924d4896965f708be022bf1b35ba
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:34:13 2021
Add a fake OnBackPressedDispatcher to Compose Previews
Rather than having APIs that depend on
LocalOnBackPressedDispatcher crash in @Preview,
provide a fake implementation by default to mirror
the capabilities that are available by default
in a ComponentActivity.
Relnote: "Compose `@Preview` now provides a
`LocalOnBackPressedDispatcherOwner` that allows you
to preview Composables that use APIs like `BackHandler`
that depend on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ia1c05ea3cadf2fb55cef9c4b8bae0898cfb35ba9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
ma...@google.com <ma...@google.com> #6
We've added default a LocalOnBackPressedDispatcherOwner
and LocalActivityResultRegistryOwner
to @Preview
, so APIs that depend on these existing won't crash out of the box.
si...@google.com <si...@google.com> #7
Thanks!
ex...@gmail.com <ex...@gmail.com> #8
I don't know how much start padding Gmail uses but I tried 15.dp in my Compose example and it still does not help.
ex...@gmail.com <ex...@gmail.com> #9
And while I'm here, looking at the Gmail vs Compose screenshot I'm reminded that I could really make use of a "Select all" feature in Compose :).
si...@google.com <si...@google.com>
qq...@google.com <qq...@google.com> #10
The way how Android and Chrome can select the first word is by word-based selection when dragging the left handle into the first word's visual range.
si...@google.com <si...@google.com> #11
I believe this might require something else other than char based word based selection. the dup ticket might be one way of doing it however it may not solve the issue based on the video in
I wonder if when selection handle approaches or touches the edge, it should actually horizontally transform, ( going from -> to <-, or from -> to |)
Therefore this might be a UX improvement and need UX input.
Qinginq, can you please describe how the dup ticket would help in this case?
si...@google.com <si...@google.com> #12
(actually looking at the video in
qq...@google.com <qq...@google.com> #13
But when the first word is partially selected, then the selection became char-based anyway.
I think it may have something to do with dragging handle and handle's position is completely inside the screen (vs. partially inside).
The dragging gesture detector is attached to the handle (popup window), so it can't go to the left?
I could be wrong. But anyway the handle's position needs to be fixed too.
qq...@google.com <qq...@google.com> #15
Since this is a public bug, I will not mark it as duplicate.
si...@google.com <si...@google.com> #16
Just to make sure: the exact same behavior happens on android Text as well (handle disappearing completely). Is it correct?
qq...@google.com <qq...@google.com> #17
The attachment shows the selection in a single TextView without padding. The left selection handle disappears completely when the first word is selected.
si...@google.com <si...@google.com> #18
Thank you very much Qingqing.
ap...@google.com <ap...@google.com> #19
Branch: androidx-main
commit c3953106eb37da7dbeff1ae7ca8d9f92223061df
Author: Qingqing Deng <qqd@google.com>
Date: Mon Apr 26 12:46:12 2021
[Text Selection] Clip Selection Handle
Bug:185942455
Bug:183408447
Test: ./gradlew test
RelNote: Clip Selection Handle
Change-Id: Iff80d27fbac0e4de5e3e99fac4352cd6ef2cd201
M compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text/selection/AndroidSelectionHandles.android.kt
M compose/ui/ui/api/public_plus_experimental_1.0.0-beta06.txt
M compose/ui/ui/api/public_plus_experimental_1.0.0-beta07.txt
M compose/ui/ui/api/public_plus_experimental_current.txt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt
qq...@google.com <qq...@google.com>
ex...@gmail.com <ex...@gmail.com> #20
I retried the original example (as described in
As a slight variation of the problem, modify the example to replace line 1 ("This text is selectable") with one long word (I actually tried a number, "1234567890123456789") and 1) select it (that works) 2) drag the left handle right and release it somewhere within the number 3) try to drag left again and select the whole number (very hard to do). (If you don't release before dragging left it works.)
This issue shows up in my real app as well (I don't have zero padding, but I guess not "enough").
ex...@gmail.com <ex...@gmail.com> #21
I still see this issue on beta09. I suppose I will have to file a new issue since this one is 'Fixed (Verified)'?
ex...@gmail.com <ex...@gmail.com> #22
The behavior I described in
cl...@google.com <cl...@google.com>
ha...@google.com <ha...@google.com>
ha...@google.com <ha...@google.com> #23
I've checked the framework TextView
behavior and noticed a different handle drag behavior from Compose selection:
So in TextView
when the left handle is at the word bound, dragging it left will extend the handle to the previous word boundary. Check the screen record attached. And this feature is helping user to selection the text at left boundary.
ha...@google.com <ha...@google.com> #24
Also checked that Chrome has similar behavior. Now working on implement a similar behavior in Compose SelectionContainer
.
ha...@google.com <ha...@google.com> #25
The remaining work is more related to
Description
Jetpack Compose Beta02, AS Canary 10
Using
SelectionContainer
without start padding, you can't select a word midsentence and drag the text selection handle left to include the first word -- unless you have sufficient start padding.To reproduce:
PartiallySelectableText()
fromIf you include
Column (modifier = Modifier.padding(start = 25.dp))
, it works as expected.