Action that an autofill service can invoke to fill the component with data.
AutofillableTextFieldWithFillableDataSemantics
@Composable
fun AutofillableTextFieldWithFillableDataSemantics() {
val state = rememberTextFieldState()
TextField(
state = state,
label = { Text("Enter your username here.") },
modifier =
Modifier.semantics {
contentType = ContentType.Username
// Set the fillable data with semantics.
FillableData.createFromText(state.text)?.let { fillableData = it }
// Replace the state value with data from the autofill provider.
onFillData { savedAutofillValue ->
savedAutofillValue.textValue?.let { state.edit { replace(0, length, it) } }
true
}
},
)
}