Brady Aiello
04/22/2021, 8:57 PM@ExperimentalComposeUiApi
@Composable
fun UsernameTextField(
state: State<String>,
label: String,
onValueChange: (String) -> Unit
) {
Column {
TextField(
value = state.value,
onValueChange = onValueChange,
label = { Text(label) },
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
singleLine = true
)
}
}
and call it like this:
UsernameTextField(
state = userName,
label = getString(R.string.Username),
) {
loginViewModel.updateUserName(it)
}
When typing most characters, the onValueChange
is triggered on the whole String there, like “a”, “ad”, “ada”. But if I type a tab or return at the end of a String, onValueChange
is triggered on only the tab/return character. Does anyone understand why this is happening?Zach Klippenstein (he/him) [MOD]
04/22/2021, 9:00 PMZach Klippenstein (he/him) [MOD]
04/22/2021, 9:01 PMBrady Aiello
04/22/2021, 9:01 PMBrady Aiello
04/22/2021, 9:02 PMZach Klippenstein (he/him) [MOD]
04/22/2021, 9:03 PMBrady Aiello
04/22/2021, 9:03 PMZach Klippenstein (he/him) [MOD]
04/22/2021, 9:03 PMdewildte
04/22/2021, 9:53 PMdewildte
04/22/2021, 9:54 PMBrady Aiello
04/22/2021, 9:59 PMdewildte
04/23/2021, 1:50 AMdewildte
04/23/2021, 1:52 AMBrady Aiello
04/23/2021, 2:04 AMBrady Aiello
04/23/2021, 2:17 AMval userName = MutableStateFlow("")
fun updateUserName(userName: String) {
val temp = userName.filterNot { it.isWhitespace() }
if (temp.isNotEmpty()) {
this.userName.value = temp
} else if (userName == "") {
this.userName.value = ""
}
}
dewildte
04/23/2021, 5:46 AMval userName = mutableStateOf(TextFieldValue(text = ""))
fun updateUserName(nextName: TextFieldValue) {
val bad = nextName.text.firstOrNull { it.isWhitespace() && it != ' ' } != null
if (bad) {
shiftFocus()
} else {
this.userName.value = nextName
}
}
I was thinking more along the lines of this.Siyamed
04/23/2021, 4:35 PMBut if I type a tab or return at the end of a String,This sounds like a bug, and I didnt understand how it would happen, please create a bug or add info to the bug Zach mentioned.is triggered on only the tab/return characteronValueChange
Siyamed
04/23/2021, 4:36 PMSiyamed
04/23/2021, 4:37 PMdewildte
04/23/2021, 4:51 PM