Madhava
07/13/2020, 12:46 AMfun onImeActionPerformed(action: ImeAction, keyboard: SoftwareKeyboardController?): Unit {
Log.v("conditions", "ime pressed $action $keyboard")
}
OutlinedTextField(
value = searchState.value,
onValueChange = { it: String ->
Log.v("conditions", "search bar $it")
searchState.value = it
},
activeColor = primaryColor,
inactiveColor = primaryColor,
label = { Text("Search") },
onFocusChange = { it: Boolean ->
Log.v("conditions", "focus changed $it")
},
imeAction = ImeAction.Search,
keyboardType = KeyboardType.Ascii,
onImeActionPerformed = { action, kb -> onImeActionPerformed(action, kb) },
modifier = Modifier.fillMaxWidth()
)
This does not:
fun onImeActionPerformed(action: ImeAction, keyboard: SoftwareKeyboardController?): Unit {
Log.v("conditions", "ime pressed $action $keyboard")
}
OutlinedTextField(
value = searchState.value,
onValueChange = { it: String ->
Log.v("conditions", "search bar $it")
searchState.value = it
},
activeColor = primaryColor,
inactiveColor = primaryColor,
label = { Text("Search") },
onFocusChange = { it: Boolean ->
Log.v("conditions", "focus changed $it")
},
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Ascii,
onImeActionPerformed = onImeActionPerformed,
modifier = Modifier.fillMaxWidth()
)
Error:
None of the following functions can be called with the arguments supplied:
public fun OutlinedTextField(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, label: () -> Unit, modifier: Modifier = ..., textStyle: TextStyle = ..., placeholder: (() -> Unit)? = ..., leadingIcon: (() -> Unit)? = ..., trailingIcon: (() -> Unit)? = ..., isErrorValue: Boolean = ..., visualTransformation: VisualTransformation = ..., keyboardType: KeyboardType = ..., imeAction: ImeAction = ..., onImeActionPerformed: (ImeAction, SoftwareKeyboardController?) -> Unit = ..., onFocusChange: (Boolean) -> Unit = ..., onTextInputStarted: (SoftwareKeyboardController) -> Unit = ..., activeColor: Color = ..., inactiveColor: Color = ..., errorColor: Color = ...): Unit defined in androidx.ui.material
public fun OutlinedTextField(value: String, onValueChange: (String) -> Unit, label: () -> Unit, modifier: Modifier = ..., textStyle: TextStyle = ..., placeholder: (() -> Unit)? = ..., leadingIcon: (() -> Unit)? = ..., trailingIcon: (() -> Unit)? = ..., isErrorValue: Boolean = ..., visualTransformation: VisualTransformation = ..., keyboardType: KeyboardType = ..., imeAction: ImeAction = ..., onImeActionPerformed: (ImeAction, SoftwareKeyboardController?) -> Unit = ..., onFocusChange: (Boolean) -> Unit = ..., onTextInputStarted: (SoftwareKeyboardController) -> Unit = ..., activeColor: Color = ..., inactiveColor: Color = ..., errorColor: Color = ...): Unit defined in androidx.ui.material
V Badalyan
07/13/2020, 1:38 AMV Badalyan
07/13/2020, 1:38 AMV Badalyan
07/13/2020, 1:38 AMMadhava
07/13/2020, 2:33 AMMadhava
07/13/2020, 2:33 AMvar searchState = TextFieldValue()
Box(paddingTop = 0.dp, paddingBottom = 10.dp) {
fun onImeActionPerformed(action: ImeAction, keyboard: SoftwareKeyboardController?): Unit {
Log.v("conditions", "ime pressed $action $keyboard")
}
OutlinedTextField(
value = TextFieldValue(),
onValueChange = {
Log.v("conditions", "search bar $it")
searchState = TextFieldValue(text = searchState.text + it.text)
},
activeColor = primaryColor,
inactiveColor = primaryColor,
label = { Text("Search") },
onFocusChange = { it: Boolean ->
Log.v("conditions", "focus changed $it")
},
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Ascii,
onImeActionPerformed = { action, kb ->
Log.v("conditions", "test got executed")
onImeActionPerformed(action, kb)
},
modifier = Modifier.fillMaxWidth()
)
}
Madhava
07/13/2020, 2:34 AMMadhava
07/13/2020, 2:34 AMMadhava
07/13/2020, 2:35 AMMadhava
07/13/2020, 2:39 AMonValueChange = {
Log.v("conditions", "search bar $it")
searchState.value = it
},
but as i said no ime or keyboard changes, does anyone know why?Zach Klippenstein (he/him) [MOD]
07/13/2020, 1:38 PMTextFieldValue()
is just a simple constructor call, so yes you'd need to wrap it with state {}
or you'll be creating a new value on every composition and none of the changes you make to it will be observed or applied (although this might depend on the version of Compose?)Zach Klippenstein (he/him) [MOD]
07/13/2020, 1:40 PM::onImeActionPerformed
Zach Klippenstein (he/him) [MOD]
07/13/2020, 1:47 PMTextFieldValue
is just a simple Immutable value type, basically. It represents the entire state of the text + selection. The text field will use whatever value you pass in on every composition. So just like any other state that you want to change over time, you need to use state{}
so that the value will be remembered between compositions. I think there's also an overload that only takes a String, which you can use if you don't need to control the selection/cursor state. In that case, you would need to use state{}
for the string value.Madhava
07/13/2020, 11:41 PMZach Klippenstein (he/him) [MOD]
07/16/2020, 4:57 PMEditText
should solve all those problems, yea.