diff --git a/presentation/src/main/java/com/whyranoid/presentation/compose/DropDownMenu.kt b/presentation/src/main/java/com/whyranoid/presentation/compose/DropDownMenu.kt index aa70cb28..22b20ba2 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/compose/DropDownMenu.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/compose/DropDownMenu.kt @@ -1,6 +1,7 @@ package com.whyranoid.presentation.compose -import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.shape.RoundedCornerShape @@ -15,6 +16,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.res.stringResource @@ -29,35 +31,41 @@ fun DateDropDownMenu( val dateText = stringResource(id = R.string.text_date) val dateList = stringArrayResource(id = R.array.rule_date_array) var isDropDownMenuExpanded by remember { mutableStateOf(false) } - Button( - onClick = { isDropDownMenuExpanded = true }, - colors = ButtonDefaults - .outlinedButtonColors( - contentColor = colorResource(id = R.color.mogakrun_on_primary) - ), - shape = RoundedCornerShape(30), - elevation = ButtonDefaults.elevation( - defaultElevation = 2.dp, - pressedElevation = 4.dp, - disabledElevation = 0.dp - ) - ) { - Text(text = selectedDate + dateText) - } + Column { + Button( + onClick = { isDropDownMenuExpanded = true }, + colors = ButtonDefaults + .outlinedButtonColors( + contentColor = colorResource(id = R.color.mogakrun_on_primary) + ), + shape = RoundedCornerShape(30), + elevation = ButtonDefaults.elevation( + defaultElevation = 2.dp, + pressedElevation = 4.dp, + disabledElevation = 0.dp + ) + ) { + Text(text = selectedDate + dateText) + } - DropdownMenu( - modifier = Modifier - .wrapContentWidth() - .wrapContentHeight(), - expanded = isDropDownMenuExpanded, - onDismissRequest = { isDropDownMenuExpanded = false } - ) { - dateList.forEach { date -> - DropdownMenuItem(onClick = { - onDateSelected(date) - isDropDownMenuExpanded = false - }) { - Text(text = date + dateText) + DropdownMenu( + modifier = Modifier + .wrapContentWidth() + .wrapContentHeight() + .heightIn( + 0.dp, + LocalConfiguration.current.screenHeightDp.dp / 2 - ButtonDefaults.MinHeight + ), + expanded = isDropDownMenuExpanded, + onDismissRequest = { isDropDownMenuExpanded = false } + ) { + dateList.forEach { date -> + DropdownMenuItem(onClick = { + onDateSelected(date) + isDropDownMenuExpanded = false + }) { + Text(text = date + dateText) + } } } } @@ -71,35 +79,41 @@ fun HourDropDownMenu( val hourText = stringResource(id = R.string.text_hour) val hourList = stringArrayResource(id = R.array.rule_hour_array) var isDropDownMenuExpanded by remember { mutableStateOf(false) } - Button( - onClick = { isDropDownMenuExpanded = true }, - colors = ButtonDefaults - .outlinedButtonColors( - contentColor = colorResource(id = R.color.mogakrun_on_primary) - ), - shape = RoundedCornerShape(30), - elevation = ButtonDefaults.elevation( - defaultElevation = 2.dp, - pressedElevation = 4.dp, - disabledElevation = 0.dp - ) - ) { - Text(text = selectedHour + hourText) - } + Column { + Button( + onClick = { isDropDownMenuExpanded = true }, + colors = ButtonDefaults + .outlinedButtonColors( + contentColor = colorResource(id = R.color.mogakrun_on_primary) + ), + shape = RoundedCornerShape(30), + elevation = ButtonDefaults.elevation( + defaultElevation = 2.dp, + pressedElevation = 4.dp, + disabledElevation = 0.dp + ) + ) { + Text(text = selectedHour + hourText) + } - DropdownMenu( - modifier = Modifier - .wrapContentWidth() - .height(500.dp), - expanded = isDropDownMenuExpanded, - onDismissRequest = { isDropDownMenuExpanded = false } - ) { - hourList.forEach { hour -> - DropdownMenuItem(onClick = { - onHourSelected(hour) - isDropDownMenuExpanded = false - }) { - Text(text = hour + hourText) + DropdownMenu( + modifier = Modifier + .wrapContentWidth() + .wrapContentHeight() + .heightIn( + 0.dp, + LocalConfiguration.current.screenHeightDp.dp / 2 - ButtonDefaults.MinHeight + ), + expanded = isDropDownMenuExpanded, + onDismissRequest = { isDropDownMenuExpanded = false } + ) { + hourList.forEach { hour -> + DropdownMenuItem(onClick = { + onHourSelected(hour) + isDropDownMenuExpanded = false + }) { + Text(text = hour + hourText) + } } } } @@ -114,35 +128,41 @@ fun MinuteDropDownMenu( val minuteList = stringArrayResource(id = R.array.rule_minute_array) var isDropDownMenuExpanded by remember { mutableStateOf(false) } - Button( - onClick = { isDropDownMenuExpanded = true }, - colors = ButtonDefaults - .outlinedButtonColors( - contentColor = colorResource(id = R.color.mogakrun_on_primary) - ), - shape = RoundedCornerShape(30), - elevation = ButtonDefaults.elevation( - defaultElevation = 2.dp, - pressedElevation = 4.dp, - disabledElevation = 0.dp - ) - ) { - Text(text = selectedMinute + minuteText) - } + Column { + Button( + onClick = { isDropDownMenuExpanded = true }, + colors = ButtonDefaults + .outlinedButtonColors( + contentColor = colorResource(id = R.color.mogakrun_on_primary) + ), + shape = RoundedCornerShape(30), + elevation = ButtonDefaults.elevation( + defaultElevation = 2.dp, + pressedElevation = 4.dp, + disabledElevation = 0.dp + ) + ) { + Text(text = selectedMinute + minuteText) + } - DropdownMenu( - modifier = Modifier - .wrapContentWidth() - .height(500.dp), - expanded = isDropDownMenuExpanded, - onDismissRequest = { isDropDownMenuExpanded = false } - ) { - minuteList.forEach { minute -> - DropdownMenuItem(onClick = { - onMinuteSelected(minute) - isDropDownMenuExpanded = false - }) { - Text(text = minute + minuteText) + DropdownMenu( + modifier = Modifier + .wrapContentWidth() + .wrapContentHeight() + .heightIn( + 0.dp, + LocalConfiguration.current.screenHeightDp.dp / 2 - ButtonDefaults.MinHeight + ), + expanded = isDropDownMenuExpanded, + onDismissRequest = { isDropDownMenuExpanded = false } + ) { + minuteList.forEach { minute -> + DropdownMenuItem(onClick = { + onMinuteSelected(minute) + isDropDownMenuExpanded = false + }) { + Text(text = minute + minuteText) + } } } }