Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Subtitle is only available on iOS 15+.

System icon refers to an icon name within [SF Symbols](https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/) on IOS and Drawable name on Android.

Destructive items are rendered in red on iOS, and unchanged on Android.
Destructive items are rendered in red.

Selected items have a checkmark next to them on iOS, and unchanged on Android.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.mpiannucci.reactnativecontextmenu;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.gesture.Gesture;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
Expand Down Expand Up @@ -103,10 +108,19 @@ public void setActions(@Nullable ReadableArray actions) {
for (int i = 0; i < actions.size(); i++) {
ReadableMap action = actions.getMap(i);
@Nullable Drawable systemIcon = getResourceWithName(getContext(), action.getString("systemIcon"));
String title = action.getString("title");
int order = i;
menu.add(Menu.NONE, Menu.NONE, order, action.getString("title"));
menu.add(Menu.NONE, Menu.NONE, order, title);
menu.getItem(i).setEnabled(!action.hasKey("disabled") || !action.getBoolean("disabled"));
menu.getItem(i).setIcon(systemIcon);
if (action.hasKey("destructive") && action.getBoolean("destructive")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menu.getItem(i).setIconTintList(ColorStateList.valueOf(Color.RED));
}
SpannableString redTitle = new SpannableString(title);
redTitle.setSpan(new ForegroundColorSpan(Color.RED), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
menu.getItem(i).setTitle(redTitle);
}
}
}

Expand Down