Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isCheckable from state prop #872

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading