Advertisement
BojanNovakovic

Untitled

May 8th, 2024
1,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.89 KB | None | 0 0
  1. @OptIn(ExperimentalFoundationApi::class)
  2. @Composable
  3. fun MovesetOutlineTextField(
  4.     value: String,
  5.     onValueChange: (String) -> Unit,
  6.     onClear: () -> Unit,
  7.     modifier: Modifier = Modifier,
  8.     enabled: Boolean = true,
  9.     label: String? = null,
  10.     placeholder: String? = null,
  11.     errorText: String? = null
  12. ) {
  13.     Column {
  14.         OutlinedTextField(
  15.             value = value,
  16.             onValueChange = onValueChange,
  17.             singleLine = true,
  18.             label = { label?.let { Text(it) } },
  19.             enabled = enabled,
  20.             readOnly = !enabled,
  21.             placeholder = { placeholder?.let { Text(it) } },
  22.             modifier = modifier,
  23.             textStyle = TextStyle(color = colorResource(MR.colors.font_on_surface_color)),
  24.             trailingIcon = {
  25.                 if (enabled) {
  26.                     val trailingIconEnabled = value.isNotEmpty() && enabled
  27.                     InputCloseIcon(onClick = onClear, trailingIconEnabled)
  28.                 }
  29.             },
  30.             isError = !errorText.isNullOrEmpty()
  31.         )
  32.          val errorString = errorText ?: ""
  33.  
  34.         Text(
  35.             text = errorString,
  36.             style = TextStyle(color = colorResource(MR.colors.alert_text_on_surface_color)),
  37.             fontSize = 14.sp,
  38.             maxLines = 1,
  39.             modifier = Modifier.basicMarquee(delayMillis = 0, initialDelayMillis = 1200)
  40.         )
  41.  
  42.     }
  43. }
  44.  
  45. @Composable
  46. private fun InputCloseIcon(onClick: () -> Unit, enabled: Boolean) {
  47.     val resource = if (enabled) MR.colors.secondary_button_content_color else MR.colors.disabled_element_tint
  48.     IconButton(onClick = onClick, enabled = enabled) {
  49.         Image(
  50.             painter = painterResource(MR.images.close_image),
  51.             contentDescription = stringResource(MR.strings.close),
  52.             colorFilter = ColorFilter.tint(colorResource(resource))
  53.         )
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement