1

I have a column, that contain few TextFields. This column is bigger than screen of the device, so it's scrollable. I want to ClearFocus for TextFields when user scrolles screen.

I came up with such solution:
Created scroll state and added it to my Column;
For each of TextField's added callback when they focus get changed and storing this value in parent composable;
For clearing focus i use this code:

            val textFieldsHasFocus = textField1IsFocused || textField2IsFocused
            if (scrollState.isScrollInProgress && textFieldsHasFocus)
                focusManager.clearFocus()

I wonder if there is a better solution? Perhaps Compose have something out of the box?

0 Answers0