When you have a screen with multiple `BaseTextFiel...
# compose
m
When you have a screen with multiple
BaseTextField
, is there a convenient way to persist the focus on config changes? It's currently clearing the focus and I'm having to manage it myself by requesting the focus on the last focused text field on
LaunchedEffect
đź‘€ 1
m
The most relevant config change in this context is probably turning your device. So, why don’t you just switch off the corresponding resets in the manifest and let Compose handle the device rotation? It makes life so much easier.
c
I would have thought this works out of the box? But like Michael said... adam powell suggested you can turn off config changes entirely. (which doesn't completely save you as wallpaper changes will still trigger a config that you can't opt out.) but it is an option
m
The question is whether it is really worth the effort to constantly persist everything (like a text field focus) just in case someone changes the wallpaper or any of the other less frequently used config changes. For me device rotation is the most relevant and Compose can deal with that itself easily. So, I have switched them all off and let compose deal with the situation.
c
yeah, i gotcha. but i still thought that compose handles that out of the box. but sounds like my assumption was wrong.
m
Compose does handle that out of the box but it does not switch the activity resets off. It cannot do that because you might be using other stuff than compose in your activity. The simplification I propose only works in pure Compose activities.
m
Thanks for the posts guys. This is a pure compose activity btw. I believe whether to disable the config changes or not would be a different topic. I'm more interested in understanding how this is supposed to work.
Compose can deal with that itself easily. So, I have switched them all off and let compose deal with the situation
Could you clarify this? What do you mean by "deal with" here when you disable config changes?
m
Well, you cannot switch off the config change but you can switch off the restart of the activity. So, when a config change occurs someone has to deal with it and in the case of device rotation, e.g., compose deals with that automatically without having to restart the activity. What you get is just a new screen size and compose as well as your own code have to be able to adapt to a new screen size anyway.