Skip to content

Commit

Permalink
add isCheckable from state prop (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrdz committed Sep 7, 2024
1 parent b8ff573 commit a149bbf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions android/src/main/java/com/reactnativemenu/MenuView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
true -> config.getArray("subactions")
else -> null
}
val menuState = config?.getString("state")

if (titleColor != null) {
menuItem.title = getMenuItemTextWithColor(menuItem.title.toString(), titleColor)
Expand Down Expand Up @@ -153,6 +154,15 @@ class MenuView(private val mContext: ReactContext): ReactViewGroup(mContext) {
}
}

// Handle menuState for checkable items
when (menuState) {
"on", "off" -> {
menuItem.isCheckable = true
menuItem.isChecked = menuState == "on"
}
else -> menuItem.isCheckable = false
}

// On Android SubMenu cannot contain another SubMenu, so even if there are subactions provided
// we are checking if item has submenu (which will occur only for 1 lvl nesting)
if (subactions != null && menuItem.hasSubMenu()) {
Expand Down

0 comments on commit a149bbf

Please sign in to comment.