Skip to content

Commit

Permalink
Merge pull request #13 from mende273/create_TopMenuItem_composable
Browse files Browse the repository at this point in the history
Create TopMenuItem composable
  • Loading branch information
mende273 authored Mar 7, 2023
2 parents 08cde83 + e3705ba commit 9b86615
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 9b86615

Please sign in to comment.