Created
August 22, 2022 08:52
-
-
Save markchristopherng/2b5f8a6ef515d0decd8088224e5b4121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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