Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @OptIn(ExperimentalFoundationApi::class)
- @Composable
- fun MovesetOutlineTextField(
- value: String,
- onValueChange: (String) -> Unit,
- onClear: () -> Unit,
- modifier: Modifier = Modifier,
- enabled: Boolean = true,
- label: String? = null,
- placeholder: String? = null,
- errorText: String? = null
- ) {
- Column {
- OutlinedTextField(
- value = value,
- onValueChange = onValueChange,
- singleLine = true,
- label = { label?.let { Text(it) } },
- enabled = enabled,
- readOnly = !enabled,
- placeholder = { placeholder?.let { Text(it) } },
- modifier = modifier,
- textStyle = TextStyle(color = colorResource(MR.colors.font_on_surface_color)),
- trailingIcon = {
- if (enabled) {
- val trailingIconEnabled = value.isNotEmpty() && enabled
- InputCloseIcon(onClick = onClear, trailingIconEnabled)
- }
- },
- isError = !errorText.isNullOrEmpty()
- )
- val errorString = errorText ?: ""
- Text(
- text = errorString,
- style = TextStyle(color = colorResource(MR.colors.alert_text_on_surface_color)),
- fontSize = 14.sp,
- maxLines = 1,
- modifier = Modifier.basicMarquee(delayMillis = 0, initialDelayMillis = 1200)
- )
- }
- }
- @Composable
- private fun InputCloseIcon(onClick: () -> Unit, enabled: Boolean) {
- val resource = if (enabled) MR.colors.secondary_button_content_color else MR.colors.disabled_element_tint
- IconButton(onClick = onClick, enabled = enabled) {
- Image(
- painter = painterResource(MR.images.close_image),
- contentDescription = stringResource(MR.strings.close),
- colorFilter = ColorFilter.tint(colorResource(resource))
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement