Do we have an option of manual storing and restori...
# compose
r
Do we have an option of manual storing and restoring component state like focus, list current index? There is problem when component is rendered conditionally
if(state.loading) {
ShowLoading()
} else {
LazyColumn{}
}
Slack Conversation
b
If it's just srcoll state you want, you can hoist the LazyColumn's state out into the outer composable
If you want to preserve the state all the way down, you could leave it in the composition but hide it instead (e.g. make it's opacity=0), just like you would do with Android views
🙏 1
r
Thanks What about focus state of a TextField?
For example: I have multiple TextFields in a Column and delete button for each item. When I delete a focused TextField item I want to focus nearest TextField. How can I achieve it? @Brian G
z
You could use
FocusManager.moveFocus()
(get a
FocusManager
from
LocalFocusManager
)
r
@Zach Klippenstein (he/him) [MOD] I have a state of list of edit texts when I click delete button the state changes and compose recomposes with new data? When should I call moveFocus?
z
Good question. I think onDispose might be too late.
r
When you delete a focused item it ends up clearing focus. I think you should move focus before you delete the item.
r
Another example is "never editable" helper TextField (type a note) which on start editing adds an extra TextField to previous position. When an extra TextField added user should continue editing on it not the the helper TextField
r
Is this an example of placeholder text, that is replaced by actual text when the user types? Here are some options: 1. You can get this feature for free by using an OutlinedTextField (It has a placeholder parameter) 2. You could check the contents of the textfield in onValueChanged, and if the previous content is "type a note", you can clear the text before adding the new characters. If you still want to use two TextFields, then when the helper TextField gets focus, you can add a new TextField transfer focus to it using a Modifier.focusRequester(). If you end up choosing this option, I would suggest using a Text component instead of TextField for the "type a note" text, and use a Modifier.clickable() to add the new TextField and request focus.
🙏 1