From f8dcbfdc708e8c505c376c89ed4a984498295ff0 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 12 Dec 2024 15:17:44 +0100 Subject: [PATCH] fix: [ANDROAPP-6579] set dropdownmenu max width to 70% of screen size (#3905) * fix: set dropdownmenu max width to 70% of screen size * fix:[ANDROAPP-6579] modify offset for dropdown menu in teiDashboard --------- Co-authored-by: Xavier Molloy --- .../dhis2/utils/customviews/MoreMenuView.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/dhis2/utils/customviews/MoreMenuView.kt b/app/src/main/java/org/dhis2/utils/customviews/MoreMenuView.kt index b01a0607f2..dbcc3cd84f 100644 --- a/app/src/main/java/org/dhis2/utils/customviews/MoreMenuView.kt +++ b/app/src/main/java/org/dhis2/utils/customviews/MoreMenuView.kt @@ -1,13 +1,18 @@ package org.dhis2.utils.customviews +import android.content.res.Resources +import androidx.compose.foundation.layout.widthIn import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.MoreVert import androidx.compose.material3.Icon import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.DpOffset import org.hisp.dhis.mobile.ui.designsystem.component.IconButton import org.hisp.dhis.mobile.ui.designsystem.component.menu.DropDownMenu import org.hisp.dhis.mobile.ui.designsystem.component.menu.MenuItemData +import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor @Composable @@ -29,13 +34,20 @@ fun MoreOptionsWithDropDownMenuButton( ) { onMenuToggle(!expanded) } - DropDownMenu( + modifier = Modifier.widthIn(max = 0.7.dw), items = dropDownMenuItems, expanded = expanded, + offset = DpOffset(x = -Spacing.Spacing16, y = Spacing.Spacing0), onDismissRequest = { onMenuToggle(false) }, - ) { itemId -> - onMenuToggle(false) - onItemClick(itemId) - } + onItemClick = { itemId -> + onMenuToggle(false) + onItemClick(itemId) + }, + ) } + +inline val Double.dw: Dp + get() = Resources.getSystem().displayMetrics.let { + Dp(value = ((this * it.widthPixels) / it.density).toFloat()) + }