Skip to content

Instantly share code, notes, and snippets.

@markchristopherng
Created August 22, 2022 08:52
Show Gist options
  • Save markchristopherng/2b5f8a6ef515d0decd8088224e5b4121 to your computer and use it in GitHub Desktop.
Save markchristopherng/2b5f8a6ef515d0decd8088224e5b4121 to your computer and use it in GitHub Desktop.
@OptIn(ExperimentalAnimationGraphicsApi::class)
@Composable
fun APTextField(
modifier: Modifier = Modifier,
value: String? = null,
onValueChange: (String) -> Unit,
onEndIconClicked: () -> Unit = { },
label: String? = null,
mode: APTextFieldType = APTextFieldType.Normal
) {
val text = remember(key1 = value) { mutableStateOf(value) }
var visualTransformation = VisualTransformation.None
var trailingIcon: @Composable () -> Unit = { }
when (mode) {
APTextFieldType.ClearText -> {
trailingIcon = {
if (text.value?.isNotEmpty() == true) {
IconButton(onClick = {
text.value = ""
onValueChange("")
onEndIconClicked()
}) {
Icon(
painter = painterResource(id = com.google.android.material.R.drawable.mtrl_ic_cancel),
contentDescription = stringResource(id = R.string.textfield_clear_text_accessibility)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment