Skip to content

Commit

Permalink
Add regularIconTint color option
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobras committed May 18, 2023
1 parent 80fa594 commit 9091269
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fun ActionMenu(
IconActionItem(
modifier = Modifier.testTag("ActionMenu#${item.key}"),
item = item,
tint = colors.regularIconTint,
showSubMenu = { subMenuContent = it },
hideSubMenu = { subMenuContent = emptyList() }
)
Expand All @@ -76,14 +77,14 @@ fun ActionMenu(
modifier = Modifier.testTag("ActionMenu#overflow"),
onClick = { showOverflowMenu = true }
) {
Icon(Icons.Default.MoreVert, "More actions", tint = MaterialTheme.colors.onPrimary)
Icon(Icons.Default.MoreVert, "More actions", tint = colors.regularIconTint)
}
}

DropdownMenu(
modifier = Modifier
.width(240.dp)
.background(colors.backgroundColor),
.background(colors.dropdownBackgroundColor),
offset = DpOffset(0.dp, (-10).dp),
expanded = showOverflowMenu || subMenuContent.isNotEmpty(),
onDismissRequest = { showOverflowMenu = false; subMenuContent = emptyList() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package nl.jacobras.composeactionmenu
import androidx.compose.ui.graphics.Color

interface ActionMenuColors {
val backgroundColor: Color
val iconTint: Color
val regularIconTint: Color
val dropdownBackgroundColor: Color
val dropdownIconTint: Color
}

data class DefaultActionMenuColors(
override val backgroundColor: Color = Color.White,
override val iconTint: Color = Color(135, 135, 135)
override val regularIconTint: Color = Color.White,
override val dropdownBackgroundColor: Color = Color.White,
override val dropdownIconTint: Color = Color(135, 135, 135)
) : ActionMenuColors
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -19,6 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview
internal fun IconActionItem(
modifier: Modifier = Modifier,
item: ActionItem,
tint: Color = DefaultActionMenuColors().regularIconTint,
showSubMenu: (items: List<ActionItem>) -> Unit = {},
hideSubMenu: () -> Unit = {}
) {
Expand Down Expand Up @@ -50,13 +52,13 @@ internal fun IconActionItem(

if (iconPainter != null) {
IconButton(modifier = modifier, onClick = onClick, enabled = item.enabled) {
Icon(iconPainter, title, tint = MaterialTheme.colors.onPrimary)
Icon(iconPainter, title, tint = tint)
}
} else {
TextButton(modifier = modifier, onClick = onClick, enabled = item.enabled) {
Text(
text = title,
color = MaterialTheme.colors.onPrimary.copy(alpha = LocalContentAlpha.current),
color = tint.copy(alpha = LocalContentAlpha.current),
)
}
}
Expand All @@ -73,6 +75,20 @@ private fun RegularIconActionPreview() {
))
}

@Preview
@Composable
private fun BlueIconActionPreview() {
IconActionItem(
item = RegularActionItem(
key = "search",
titleResId = android.R.string.ok,
iconVector = Icons.Filled.Search,
onClick = {}
),
tint = Color.Blue
)
}

@Preview
@Composable
private fun DisabledIconActionPreview() {
Expand All @@ -96,6 +112,19 @@ private fun TextIconActionPreview() {
))
}

@Preview
@Composable
private fun BlueTextIconActionPreview() {
IconActionItem(
item = RegularActionItem(
key = "search",
titleResId = android.R.string.ok,
iconVector = null,
onClick = {}
),
tint = Color.Blue)
}

@Preview
@Composable
private fun DisabledTextIconActionPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal fun OverflowActionItem(
if (iconPainter != null) {
Icon(
painter = iconPainter,
tint = colors.iconTint,
tint = colors.dropdownIconTint,
contentDescription = null
)
}
Expand All @@ -96,7 +96,7 @@ internal fun OverflowActionItem(
is GroupActionItem -> {
Icon(
painter = painterResource(id = R.drawable.ic_menu_right),
tint = colors.iconTint,
tint = colors.dropdownIconTint,
contentDescription = null
)
Spacer(modifier = Modifier.width(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ class MainActivity : ComponentActivity() {
)
}
) {
Column(modifier = Modifier
.padding(it)
.padding(16.dp)) {
Column(
modifier = Modifier
.padding(it)
.padding(16.dp)
) {
Text("Welcome to the sample app! Try out the menu options above.")
Spacer(modifier = Modifier.height(8.dp))
Text("Use location (just some example text): ${useLocation.value}")
Expand Down

0 comments on commit 9091269

Please sign in to comment.