diff --git a/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java b/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java index c6f5b9a..a166b05 100644 --- a/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java +++ b/android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java @@ -216,9 +216,16 @@ private void createContextMenuSubMenu(Menu menu, ReadableMap action, ReadableArr spannableTitle.setSpan(new CustomTypefaceSpan("", customFont), 0, title.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); } - Menu parentMenu = menu.addSubMenu(spannableTitle); + // Explicit order (matching createContextMenuAction) so the submenu is inserted at index i + // in the menu's internal item list; addSubMenu(title) alone defaults order to 0, which + // shifts the submenu to the front and makes menu.getItem(i) below target the wrong item. + Menu parentMenu = menu.addSubMenu(Menu.NONE, Menu.NONE, i, spannableTitle); @Nullable Drawable icon = getResourceWithName(getContext(), action.getString("icon")); + if (action.hasKey("iconColor") && icon != null) { + int color = Color.parseColor(action.getString("iconColor")); + icon.setTint(color); + } menu.getItem(i).setIcon(icon); // set icon to current item. for (int j = 0; j < childActions.size(); j++) {