Hi, we are on the verge of releasing our Android a...
# compose
s
Hi, we are on the verge of releasing our Android app that is built entirely in Compose 🥳🥳🥳 problem is we have a major blocker:
BasicTextField
often doesn’t bring up the keyboard when focused! When it malfunctions, the cursor is literally blinking, yet somehow the keyboard is not open. This happens on physical Pixel 4a in a release build that is deployed to the play store! Since we are chat-based communities, this is critical. How is it even possible to get into this state, and are there any workarounds/hacks that can fix this reliability bug?
👍 2
😭 3
c
And I have to add: I found sort of a workaround by making the parent
Row
clickable and using a focus requester
Basically (leaving out the details):
Copy code
val focusRequester = remember { FocusRequester() }
Row(modifier = Modifier.clickable { focusRequester.requestFocus() }) {
    BasicTextField(modifier = Modifier.focusRequester(focusRequester))
}
👍 1
s
@Cyril Find this is super helpful, i’ll try it!
😁 1
@Cyril Find in our case i have a
Box
that contains the
BasicTextField
, I tried your technique of adding clickable to the
Box
and requesting focus on the `BasicTextField`’s
focusRequester
but i can still get into a blinking cursor state without software keyboard (so far tested in debug mode connected via usb)
c
ah 😞 is it a direct child too ?
s
Yes:
Copy code
Box(modifier = modifier.clickable { focusRequester.requestFocus() }) {
   if (value.text.isEmpty()) Text(placeholder)
   BasicTextField(value = value, modifier = Modifier.focusRequester(focusRequester))
}
d
I thought of a rather horrible workaround 🙂 How about embedding pre-compose EditText somewhere and proxying a click to it? hides in bushes
c
@Sam ah well…I thought I was on to something ^^ @dimsuz yeah that could work (but it hurts 😆)
d
I wonder if there's a bug reported for this, so I could vote for fixing it.
s
i just tried adding this but it doesn’t help:
Copy code
android:windowSoftInputMode="stateAlwaysVisible"
it would really help to understand the underlying problem, how can this even be a valid state on Android? what use does it serve, unless the app somehow thinks a separate hardware keyboard is attached and being used
d
Do you reproduce this on physical device or on emulator? Sometimes keyboard behaves a little bit differently on the emulator.
s
always testing on physical device, i don’t even have the emulator installed
c
@Sam have you tried the latest snapshots by chance? I'm assuming it still happens but maybe theres a chance its been fixed?
s
@Colton Idle what are the exact steps to try the snapshots? like what must i change in build.gradle
c
Basically you add a new line in your root build.gradle to declare a new repo from where to fetch artifacts. Then change all of your ALPHA09 declarations to SNAPSHOT.
So to try the latest put this in your root dep block maven { url 'https://androidx.dev/snapshots/builds/[buildId]/artifacts/repository' } and swap buildId in the above url with 7057346 (that's the latest according to androidx.dev) then just find/replace ALPHA09 with SNAPSHOT.
s
@Colton Idle i’m using navigation
androidx.navigation:navigation-compose:1.0.0-alpha04
does that also have to be changed?
btw even though alpha09 no longer exists in my project, i get error
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.0-alpha10) expects a minimum runtime version of 1.0.0-alpha10. The version of the runtime on the classpath currently is 1.0.0-alpha09
c
no idea. sorry. I would assume that declaring alpha04 of nav should work with some fairly recent snapshots.
s
@Colton Idle is there a place in the latest source code which makes you think focusability might be improved?
c
i’m kinda lost in this source site 😅 so I don’t really get in which version it will be merged but I guess it’s coming soon™️
c
@Sam nope. Just that compose moves fast and so it seems reasonable to try the latest snapshot as it will inevitably be in alpha10/beta01
s
@Cyril Find this might work, have you found a way to compile successfully with the latest snapshots?
c
@Sam nah I’m just waiting for alpha10 (and my waorkaround does the job right now ^^)
s
ok thx, i wonder why the workaround isn’t working for me
c
yeah it’s weird, but tbh it’s so random i’m not even sure it works 100%
k
@Sam are you using
savedInstanceState
to hoist the state of
TextField
? I suspected it has to do with that and found that replacing
savedInstanceState
with
remember
seems to work sometimes. Could you give it a shot?
s
we use:
Copy code
var textState by remember { mutableStateOf(TextFieldValue()) }
@Cyril Find I was able to implement your workaround successfully! The
Box
I originally used for
clickable
was very compact, so moving clickable to the parent
Row
did the trick! Thank you so much!!
👍 2
c
ah that’s cool ! 🙂
z
I was having the same issue. the TextField get focused but keyboard dose not appear. I was using this workaround but still sometimes keyboard does not appear.