Skip to content

Commit

Permalink
Create TopMenuItem composable
Browse files Browse the repository at this point in the history
  • Loading branch information
mendejumrukovski committed Mar 7, 2023
1 parent 08cde83 commit e3705ba
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/src/main/java/com/jumrukovski/quotescompose/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,28 @@ class MainActivity : ComponentActivity() {
actionIconContentColor = MaterialTheme.colorScheme.PrimaryTextColor
),
actions = {
topMenuItems.forEach {
IconButton(onClick = { onActionClick(it) }) {
Icon(
painter = painterResource(id = R.drawable.baseline_search_24),
contentDescription = stringResource(id = R.string.action_search),
tint = MaterialTheme.colorScheme.onSurface
)
}
topMenuItems.forEach { topMenuItem ->
TopMenuItem(topMenuItem = topMenuItem, onActionClick = { onActionClick(it) })
}
}
)
}

@Composable
private fun TopMenuItem(
topMenuItem: MainActivityMenuItem,
onActionClick: (MainActivityMenuItem) -> Unit = {}
) {
IconButton(onClick = { onActionClick(topMenuItem) }) {
Icon(
painter = painterResource(id = topMenuItem.drawable),
contentDescription = topMenuItem.title,
tint = MaterialTheme.colorScheme.onSurface
)
}
}

//todo do it differently
data class MainActivityMenuItem(val title: String, @DrawableRes val drawable: Int)

@Composable
Expand Down

0 comments on commit e3705ba

Please sign in to comment.