I know a lot of this behavior is up to implementat...
# compose-android
b
I know a lot of this behavior is up to implementation. I'm just trying to gauge what's most "native". I have a Jetpack Compose app, and by default focusing a textfield puts focus on the textfield and shows the IME, hitting the back button then dismisses the IME but leaves focus on the textfield, additionally clicking any buttons or anything else that isn't a textfield still leaves the textfield focused. I've read some StackOverflow articles that people expect textfields to unfocus when tapping a clickable button, and then there's mimicing default iOS behavior where the second the ime is dismissed, focus is lost from the inputs. Additionally if a field is focused and then you navigate forward into perhaps a detail screen, when navigating back to the list screen should there be focus or no focus on the field that was focused last? Apps like Reddit when performing a search leave the TextField focused when the ime is dismissed and additionally when navigating back from a result back to the search, represents the ime and maintains focus of the textfield. Any and all insight is helpful.
z
@Ralston Da Silva
😄 1
r
In android, we have two modes touch mode and non-touch mode. These correspond to
InputMode.Touch
and
InputMode.Keyboard
in Compose. TextFields are focusable in both modes. Buttons are only focusable in Keyboard mode. The use-case described here is in touch mode, so when a text field is focused, clicking on another button doesn't cause it to lose focus. However clicking on something else that is focusable in touch mode will cause the text field to lose focus. An example usecase for this behavior: Clicking on a button to change the text style doesn't cause the textfield to lose focus, we can continue typing in the textfield. Focus restoration when we navigate back to a previous screen is a feature that isn't implemented yet.
👀 1
b
Ralston, is the focus restoration something that an android app with navigation using views would have and is just not implemented in compose? Or is this not something that any native Android app would do without a third party library or custom implementation?
r
I'm not sure if views have this behavior by default, it is something you would have to check
i
FWIW, using multiple activities does keep focus. Same with multiple fragments
🙌 1