Ivo Heberle
03/08/2024, 8:08 AMModifier.clickable{expanded = !expanded}
lambda never gets called in the desktop version, i tried setting a breakpoint there in the debugger and didn't get any breaks when clicking on it, why that is and why it worked before and still works on android i don't know.
Edit2:
if i copy paste the Modifier.clickable{expanded = !expanded}
to the trailingIcon (Image) inside the TextField i can click on that and that expands the drop-down-menu, but only if i click the icon itself, i also tried to give the surrounding box the Modifier.clickable{expanded = !expanded}
but that did not work either
@OptIn(ExperimentalMaterialApi::class, ExperimentalResourceApi::class)
@Composable
fun DropdownMenuCustom(
modifier: Modifier = Modifier,
value:String,
label:String,
onItemClick: (String)->Unit
){
var expanded by remember { mutableStateOf(false) }
var icon:ImageVector
var labelColor: Color
var bottomLineColor:Color
var bottomLineThickness: Dp
if(expanded){
icon = Icons.Filled.KeyboardArrowUp
labelColor = MaterialTheme.colors.primary.copy(ContentAlpha.high)
bottomLineColor = MaterialTheme.colors.primary
bottomLineThickness = 2.dp
}else{
icon = Icons.Filled.KeyboardArrowDown
labelColor = MaterialTheme.colors.onSurface.copy(ContentAlpha.medium)
bottomLineColor = MaterialTheme.colors.onSurface.copy(ContentAlpha.medium)
bottomLineThickness = 1.dp
}
Box(modifier = modifier){
TextField(
enabled = false,
colors = TextFieldDefaults.textFieldColors(
disabledTextColor = MaterialTheme.colors.onSurface,
disabledLabelColor = labelColor
),
modifier = Modifier
.focusable(enabled = true)
.clickable {expanded = !expanded}
.indicatorLine(
enabled = true,
isError = false,
interactionSource = remember { MutableInteractionSource() },
colors = TextFieldDefaults.textFieldColors(
disabledIndicatorColor = bottomLineColor,
unfocusedIndicatorColor = bottomLineColor,
),
unfocusedIndicatorLineThickness = bottomLineThickness
)
.pointerHoverIcon(
icon = PointerIcon.Hand,
overrideDescendants = true
),
readOnly = true,
value = value,
singleLine = true,
onValueChange = {},
trailingIcon = { Image(
imageVector = icon,
contentDescription = null,
modifier = Modifier.fillMaxHeight()
)},
label = { Text(text = label)},
)
DropdownMenu(
modifier = Modifier.pointerHoverIcon(
icon = PointerIcon.Hand,
overrideDescendants = true),
expanded = expanded,
onDismissRequest = {expanded = false},
){
Currency.values.forEach{
entry ->
DropdownMenuItem(
onClick = {
onItemClick(entry.key)
expanded = false
}
){
Row (
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
){
Text(text = entry.key)
if(entry.value.drawableResource !=null){
Image(
modifier = Modifier
.width(30.dp)
.aspectRatio(4f/3f)
.border(
width = 1.dp,
color = Color(0.1f,0.1f,0.1f,0.15f))
,
painter = painterResource(entry.value.drawableResource!!),
contentDescription = "",
contentScale = ContentScale.Crop)
}
}
}
}
}
}
}
Chrimaeon
03/08/2024, 9:52 AMIvo Heberle
03/08/2024, 11:14 AM1.6.10-dev1496
first i didn't want to do that because i thought the dev version might be unstable and cause more problemsChrimaeon
03/08/2024, 12:02 PM