Skip to content

Instantly share code, notes, and snippets.

@sdzshn3
Last active September 18, 2023 09:55
Show Gist options
  • Save sdzshn3/4f14132222df30151b4bec6ab84d4e79 to your computer and use it in GitHub Desktop.
Save sdzshn3/4f14132222df30151b4bec6ab84d4e79 to your computer and use it in GitHub Desktop.
@Composable
fun MyDropDown(
modifier: Modifier = Modifier,
onClick: () -> Unit,
label: String,
placeHolder: String,
value: String,
error: String = ""
) {
Column(
modifier = modifier
) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.focusProperties {
canFocus = false
},
interactionSource = remember {
MutableInteractionSource()
}.also { interactionSource ->
LaunchedEffect(key1 = interactionSource) {
interactionSource.interactions.collect {
if (it is PressInteraction.Release) {
onClick.invoke()
}
}
}
},
value = value,
onValueChange = {},
readOnly = true,
label = {
Text(text = label)
},
placeholder = {
Text(text = placeHolder)
},
trailingIcon = {
Icon(
painter = painterResource(SharedRes.images.ic_arrow_down),
contentDescription = "Expand $label list",
tint = Color(0xFF777777),
modifier = Modifier
)
},
isError = error.isNotBlank(),
supportingText = {
if (error.isNotBlank()) {
Text(
modifier = Modifier.fillMaxWidth(),
text = error,
color = MaterialTheme.colorScheme.error
)
}
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment