From b6c0da53eb8eca66fea750630163aa74aa6f91b1 Mon Sep 17 00:00:00 2001 From: Omer Toledo Date: Sun, 2 Aug 2026 00:51:33 +0300 Subject: [PATCH] fix(android): preserve submenu order and apply iconColor tint Use addSubMenu with explicit order index so submenu items stay at the correct position instead of defaulting to order 0. Also apply iconColor to submenu parent icons, matching leaf menu item behavior. Co-authored-by: Cursor --- .../reactnativecontextmenu/ContextMenuView.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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++) {