iroyo
09/23/2022, 10:21 AM@HiltViewModel
class SearchVM @Inject constructor(
savedStateHandle: SavedStateHandle
) : ViewModel() {
var query by mutableStateOf(savedStateHandle["query"] ?: "")
private set
}
the wrapper of BaseTextField is very simple it only has:
if (autofocus) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
}
Zoltan Demant
09/23/2022, 10:31 AMTextFieldValue
which you can use to specify where the cursor should be initially. Ill attach some code below for how Ive been handling this myself, the important bit being selection
which is always the length of the input text.
var value by remember {
val textOrEmpty = text.orEmpty()
val fieldValue = TextFieldValue(
text = textOrEmpty,
selection = TextRange(textOrEmpty.length),
)
mutableStateOf(fieldValue)
}