Status Update
Comments
kl...@google.com <kl...@google.com>
kl...@google.com <kl...@google.com> #2
Branch: androidx-main
commit cb1afd67dacbf14cd22206c6f5b543dbf18cec1f
Author: Tony Mak <tonymak@google.com>
Date: Thu Jan 06 14:52:58 2022
Deprecate all the APIs in textclassifier
Bug: 210509084
Test: Check api/current.txt and ensure all classes are deprecated
Relnote: "Deprecate all the APIs in the textclassifier module"
Change-Id: Idc18063196531c0e926162fefeadf2dc5f559da1
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextSelection.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextLinks.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextClassificationSessionId.java
M textclassifier/textclassifier/api/public_plus_experimental_current.txt
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextClassification.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextClassificationManager.java
M textclassifier/textclassifier/api/current.txt
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextClassificationContext.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextLinksParams.java
M textclassifier/textclassifier/api/restricted_current.txt
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/ConversationAction.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/TextClassifier.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/ConversationActions.java
M textclassifier/textclassifier/src/main/java/androidx/textclassifier/ExtrasUtils.java
el...@gmail.com <el...@gmail.com> #3
Is there any update when the alpha04 will be available? We need it to target api 31 because of the PendingIntent mutability flags missing in alpha03.
el...@gmail.com <el...@gmail.com> #4
I'll schedule it for the next release. Note that alpha04
is a complete turn-down of the library where all APIs are marked as Deprecated
, so you'll also want to start removing your usages of the library.
kl...@google.com <kl...@google.com>
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit 19ed7e69823a09f3c63f8c8cdf339af8ca1645ab
Author: Alan Viverette <alanv@google.com>
Date: Mon Mar 14 15:18:16 2022
Bump textclassifier for final release and turn-down
Bug: 210509084
Change-Id: Ib8b2386903bb49baa3211f7de7fe1587fdda1483
Test: ./gradlew checkApi
M libraryversions.toml
ap...@google.com <ap...@google.com> #6
Bugjuggler: wait until 2022-03-23
el...@gmail.com <el...@gmail.com> #7
kl...@google.com <kl...@google.com> #8
Is there a replacement or should we just abandon TextClassifier for android older than API Level 26 ?
el...@gmail.com <el...@gmail.com> #9
Abandon. The owning team had no plans to release a replacement library.
kl...@google.com <kl...@google.com> #10
My bad, this particular bug is still not fixed in 1.4.0-alpha04 – the case where the field takes up all available space. The cases where it doesn't are fixed. No timeline to share yet for when this case will be fixed.
el...@gmail.com <el...@gmail.com> #11
Ah that's alright, it's pretty relieving to see progress as issues with TextFields and scrolling have been seeing slow progress for quite some time.
Thanks for all the efforts! Hope 1.4.0-alpha05 fixes this one.
ma...@gmail.com <ma...@gmail.com> #12
Bug is not solved in 1.4.0-alpha05
el...@gmail.com <el...@gmail.com> #13
Yep, they have no timeline for when it's going to be fixed :p
The above workaround is super inefficient for large texts, as using verticalScroll renders the entirety of the BasicTextField instead of only the visible lines (which i guess is the default behavior of BasicTextField's internal scrolling), causing a lot of lag in scrolling.
At least having something like
yv...@gmail.com <yv...@gmail.com> #14
For automatic scrolling to the clicked row, you can programmatically press the space key to focus the basictextfield on the clicked row.
You only need to do this when the keyboard is opened and there is no selected text.
val keyOpened = keyboardAsState().value == Keyboard.Opened
var noteText by remember { mutableStateOf(TextFieldValue(text = "")) }
val scope = rememberCoroutineScope()
LaunchedEffect(keyOpened){
if (keyOpened && noteText.selection.length == 0){
scope.launch(Dispatchers.IO) {
try {
val inst = Instrumentation()
delay(100)
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_SPACE)
delay(100)
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DEL)
}catch (ex: InterruptedException) {
println("Hata Key: "+ex.localizedMessage)
}
}
}
}
BasicTextField(
value = notText,
onValueChange =
{
notText = it
},
textStyle = TextStyle(
Color.Black, fontSize = 19.sp,
fontFamily = FontManager().robotFontFamily,
fontWeight = FontWeight.Normal,
textAlign = TextAlign.Start
),
cursorBrush = Brush.verticalGradient(colors = listOf(Color(0xFF199800), Color(0xFF199800))),
modifier = Modifier
.fillMaxSize()
.focusRequester(focusRequester)
.background(Color.Transparent)
) { innerText ->
innerText()
}
ja...@gmail.com <ja...@gmail.com> #15
el...@gmail.com <el...@gmail.com> #16
Yeah it kinda sucks. They seem to be doing some architectural changes to TextFields for 1.5, so fingers crossed for that.
For anyone still experiencing this, the workaround I wrote in
el...@gmail.com <el...@gmail.com> #17
Hi! The new BasicTextField2 in Compose 1.6 alphas seems really promising. For now it seems like the issue of staying on top of the keyboard while typing is fixed; however, on a long text, selecting the text in the area where the keyboard is about to show doesn't scroll the text field to keep the cursor in view.
Once that gets fixed, this issue will be fully resolved and can be effectively closed!
Any updates or ETAs on that?
na...@gmail.com <na...@gmail.com> #18
ro...@gmail.com <ro...@gmail.com> #19
Any new developments on this issue? I'm using BasicTextField to implement a rich edit window (it can attach images, etc.), but it won't keep the text above the keyboard if I add Modifier.verticalScrollable()
:(
which I think is still pretty important
ap...@google.com <ap...@google.com> #20
Branch: androidx-main
commit 6a7220cc4ecc9b6c54e2433a2ade60a360f72690
Author: Zach Klippenstein <klippenstein@google.com>
Date: Wed Jan 17 15:52:42 2024
Ensures BTF2 cursor is scrolled back into view when typing.
If the cursor is scrolled out of view, either from the field's internal
scrollable or something outside it, and the cursor is moved or text is
entered, the cursor should be scrolled back into view as long as the
field is focused. This change makes that happen for BTF2.
This supersedes my original impl, aosp/2178021.
Bug:
Test: TextFieldScrollTest
Relnote: "`BasicTextField2` now keeps the cursor in view while typing
when it has been scrolled out of view or would move out of view due
to input."
Change-Id: Ieb85691dd1a7cf98ab5fc188721d4e4475aec762
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text2/input/TextFieldScrollTest.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/CoreTextField.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/BasicTextField2.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/input/internal/TextFieldDecoratorModifier.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text2/input/internal/TextLayoutState.kt
el...@gmail.com <el...@gmail.com> #21
Looks promising! Does that mean this is finally fixed? And when can we expect this to be released so we can test it?
kl...@google.com <kl...@google.com> #22
It will be fixed in BasicTextField2
in the next 1.7.0 alpha release, alpha02. We are not planning to fix it in the current BasicTextField
.
el...@gmail.com <el...@gmail.com> #23
Great news finally!
This is a bit unrelated, but will the name of the BasicTextField2
API be always like this? Or will it eventually replace BasicTextField
?
Because with the 2
it sounds like this "secondary" thing, not like the primary API that everyone should be using.
Other than that, thanks for the amazing work!
el...@gmail.com <el...@gmail.com> #25
Great to hear! Thanks for sharing the talk, and props to you guys for this amazing work!
kl...@google.com <kl...@google.com>
ja...@gmail.com <ja...@gmail.com> #26
el...@gmail.com <el...@gmail.com> #27
ja...@gmail.com <ja...@gmail.com> #28
when it has been scrolled out of view or would move out of view due
to input." this BasicTextField2 not scrolling text above keyboard even keyboad is not opened after clicking text for the second time
el...@gmail.com <el...@gmail.com> #29
Okay I just played with the new BasicTextField... and it seems like this has been only half-fixed.
Inputting anything from the keyboard brings the cursor into focus, which is great. Adding new lines keeps the cursor in view, which is great.
However, tapping the text field (which opens the IME) in an area that will eventually be under the keyboard, does not scroll the cursor to stay in view.
My wacky workaround at the very beginning of this issue does that correctly, and not only for the keyboard, but for any size changes (my app has, in addition to system keyboard, an internal keyboard, and it works the exact same way). If the cursor is in view, I keep it in view no matter what. If the cursor has been scrolled out-of-view, then it's okay to bring it in view only once there's input from the user.
Is this behavior intended? I'm not 100% sure, but I believe that Android's EditText
was keeping the cursor in view once the IME is shown.
I can make a video demonstration with all of these (New BasicTextField, legacy BasicTextField, my workaround, and EditText)
el...@gmail.com <el...@gmail.com> #30
In terms of the keyboard not showing at all the second time you click the text field, I think that's a different bug, and should be reported as its own issue with all the context of where and how that happens to you.
Also note that BasicTextField2
from 1.6.x releases is outdated, so make sure to use the new BasicTextField
in 1.7.0 betas.
da...@gmail.com <da...@gmail.com> #31
To
el...@gmail.com <el...@gmail.com> #32
imePadding()
Modifier on the BasicTextField
, and it doesn't work even with it.
This isn't even IME-specific; any change in the TextField's size should try to keep the cursor in the viewport (if it was already visible before the size change).
imePadding
does exactly just that: add padding, which in turn shrinks the size of the BasicTextField from the bottom. Currently, the new BasicTextField does not react to this at all, thus causing the cursor to stay under the keyboard.
My workaround (from
It is still, however, a workaround (a wacky one to be clear, I'm not even sure I understand my own code, but it works flawlessly in production), and there's nothing than a proper upstream fix for everybody, that would be more performant and just less wacky.
ja...@gmail.com <ja...@gmail.com> #33
el...@gmail.com <el...@gmail.com> #34
BasicTextField2
that's in Compose 1.6.x is outdated.
If you want to try the latest API, update to Compose 1.7.0-beta03 (which is the latest beta as of now), and use BasicTextField
(which now uses the new implementation). This issue is mostly fixed in 1.7.
bringIntoViewRequester
is irrelevant here, because we're talking about the internal scroll of the text field (especially in the case when it takes full screen space). It's not about scrolling some LazyList to keep the field in view, it's about scrolling the field itself to keep the cursor in view.
Again, if you update to 1.7.0 and still face the issue of the keyboard not opening the second time, that's a different issue, please report it separately.
mi...@gmail.com <mi...@gmail.com> #35
el...@gmail.com <el...@gmail.com> #36
Modifier.imePadding()
, but the cursor will still come into view... once you type something.
However, since I still have to use the older BasicTextField
sometimes because I need AnnotatedString
, and because the current fix doesn't satisfy me, I just use a workaround for now, using BringIntoViewRequester
. It's much simpler, cleaner and easier to understand than the abomination I wrote in
To keep the cursor in view on text changes (like the current fix), you need to add a bringIntoViewRequester
to your BasicTextField
, and then get use the TextLayoutResult
from onTextLayout
to get the bounding of the current cursor position, and call request bringIntoView
using that Rect.
To complete the fix, you'll wanna store the TextLayoutResult
in a state, and add a LaunchedEffect
on TextFieldValue.selection
/TextFieldState.selection
changes, which does the exact same thing as before (calling bringIntoView
with cursor rect).
Do the same on size changes (in Modifier.onPlaced
), and you're fully set. The cursor will always be brought to view on size/selection/text changes, while still allowing users to scroll it away when none of these change, works well on desktop, and you can of course choose which triggers to keep.
You can also add some padding to the Rect
you pass to bringIntoView
, for example to keep some space between the line where the cursor is and the IME/bottom/top of screen.
I generally use this alongside a verticalScroll
modifier to apply some internal non-clipping padding, but it should work fine without it, at least on the new BasicTextField
.
Description
Hi there! I've come across a bug in Compose's BasicTextField, which is that the cursor stays behind the keyboard when the clicked line is in the place where the keyboard is about to show. This is because the BasicTextField is occupying the whole screen.
Android's TextView behaves correctly and bumps the selected line to show above the keyboard.
A video is attached with the Jetpack Compose behavior versus how it behaves with a TextView.
This bug can be reworded as "Scroll selected line into view when BasicTextField is resized", as the BasicTextField is essentially resized because of the IME insets.
Here's the code:
Note that
android:windowSoftInputMode
is set toadjustResize
.