|
|
|
@ -6,11 +6,15 @@ package org.mozilla.fenix.compose
|
|
|
|
|
|
|
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
|
import androidx.compose.foundation.layout.width
|
|
|
|
|
import androidx.compose.foundation.selection.selectable
|
|
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
import androidx.compose.material.DropdownMenu
|
|
|
|
|
import androidx.compose.material.DropdownMenuItem
|
|
|
|
|
import androidx.compose.material.Icon
|
|
|
|
|
import androidx.compose.material.MaterialTheme
|
|
|
|
|
import androidx.compose.material.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
@ -24,8 +28,11 @@ import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.platform.LocalConfiguration
|
|
|
|
|
import androidx.compose.ui.platform.testTag
|
|
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
|
|
import androidx.compose.ui.semantics.Role
|
|
|
|
|
import androidx.compose.ui.unit.DpOffset
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
|
import org.mozilla.fenix.compose.annotation.LightDarkPreview
|
|
|
|
|
import org.mozilla.fenix.compose.button.PrimaryButton
|
|
|
|
|
import org.mozilla.fenix.theme.FirefoxTheme
|
|
|
|
@ -62,14 +69,51 @@ private fun Menu(
|
|
|
|
|
.background(color = FirefoxTheme.colors.layer2)
|
|
|
|
|
.then(modifier),
|
|
|
|
|
) {
|
|
|
|
|
val hasCheckedItems = menuItems.any { it.isChecked }
|
|
|
|
|
|
|
|
|
|
for (item in menuItems) {
|
|
|
|
|
val checkmarkModifier = if (hasCheckedItems) {
|
|
|
|
|
Modifier.selectable(
|
|
|
|
|
selected = item.isChecked,
|
|
|
|
|
role = Role.Button,
|
|
|
|
|
onClick = {
|
|
|
|
|
onDismissRequest()
|
|
|
|
|
item.onClick()
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Modifier
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DropdownMenuItem(
|
|
|
|
|
modifier = Modifier.testTag(item.testTag),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.testTag(item.testTag)
|
|
|
|
|
.align(alignment = Alignment.CenterHorizontally)
|
|
|
|
|
.then(checkmarkModifier),
|
|
|
|
|
onClick = {
|
|
|
|
|
onDismissRequest()
|
|
|
|
|
item.onClick()
|
|
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
if (hasCheckedItems) {
|
|
|
|
|
if (item.isChecked) {
|
|
|
|
|
Icon(
|
|
|
|
|
painter = painterResource(id = R.drawable.mozac_ic_checkmark_24),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(24.dp),
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
tint = FirefoxTheme.colors.iconPrimary,
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Spacer(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(24.dp),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.width(12.dp))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
text = item.title,
|
|
|
|
|
color = item.color ?: FirefoxTheme.colors.textPrimary,
|
|
|
|
@ -117,12 +161,14 @@ fun ContextualMenu(
|
|
|
|
|
*
|
|
|
|
|
* @property title Text the item should display.
|
|
|
|
|
* @property color Color used to display the text.
|
|
|
|
|
* @property isChecked Whether a checkmark should appear next to the text.
|
|
|
|
|
* @property testTag Tag used to identify the item in automated tests.
|
|
|
|
|
* @property onClick Callback to be called when the item is clicked.
|
|
|
|
|
*/
|
|
|
|
|
data class MenuItem(
|
|
|
|
|
val title: String,
|
|
|
|
|
val color: Color? = null,
|
|
|
|
|
val isChecked: Boolean = false,
|
|
|
|
|
val testTag: String = "",
|
|
|
|
|
val onClick: () -> Unit,
|
|
|
|
|
)
|
|
|
|
|