Skip to content

Commit b4310f2

Browse files
authored
Fix bad merge (#55)
1 parent 7206a99 commit b4310f2

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public void setActions(ContextMenuView view, @Nullable ReadableArray actions) {
4040
view.setActions(actions);
4141
}
4242

43+
@ReactProp(name = "dropdownMenuMode")
44+
public void setDropdownMenuMode(ContextMenuView view, @Nullable boolean enabled) {
45+
view.setDropdownMenuMode(enabled);
46+
}
47+
4348
@androidx.annotation.Nullable
4449
@Override
4550
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {

android/src/main/java/com/mpiannucci/reactnativecontextmenu/ContextMenuView.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public Action(String title, boolean disabled) {
4343

4444
boolean cancelled = true;
4545

46+
protected boolean dropdownMenuMode = false;
47+
4648
public ContextMenuView(final Context context) {
4749
super(context);
4850

@@ -51,9 +53,19 @@ public ContextMenuView(final Context context) {
5153
contextMenu.setOnDismissListener(this);
5254

5355
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
56+
@Override
57+
public boolean onSingleTapConfirmed(MotionEvent e) {
58+
if (dropdownMenuMode) {
59+
contextMenu.show();
60+
}
61+
return super.onSingleTapConfirmed(e);
62+
}
63+
5464
@Override
5565
public void onLongPress(MotionEvent e) {
56-
contextMenu.show();
66+
if (!dropdownMenuMode) {
67+
contextMenu.show();
68+
}
5769
}
5870
});
5971
}
@@ -88,6 +100,10 @@ public void setActions(@Nullable ReadableArray actions) {
88100
}
89101
}
90102

103+
public void setDropdownMenuMode(@Nullable boolean enabled) {
104+
this.dropdownMenuMode = enabled;
105+
}
106+
91107
@Override
92108
public boolean onMenuItemClick(MenuItem menuItem) {
93109
cancelled = false;

ios/ContextMenu.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ @implementation ContextMenu
66
RCT_EXPORT_MODULE()
77

88
- (UIView *) view {
9-
return [[ContextMenuView alloc] init];
9+
ContextMenuView *contextMenuView = [[ContextMenuView alloc] init];
10+
return contextMenuView;
1011
}
1112

1213
RCT_EXPORT_VIEW_PROPERTY(title, NSString)
@@ -16,5 +17,12 @@ - (UIView *) view {
1617
RCT_CUSTOM_VIEW_PROPERTY(previewBackgroundColor, UIColor, ContextMenuView) {
1718
view.previewBackgroundColor = json != nil ? [RCTConvert UIColor:json] : nil;
1819
}
20+
RCT_CUSTOM_VIEW_PROPERTY(dropdownMenuMode, BOOL, ContextMenuView) {
21+
if (@available(iOS 14.0, *)) {
22+
view.showsMenuAsPrimaryAction = json != nil ? [RCTConvert BOOL:json] : view.showsMenuAsPrimaryAction;
23+
} else {
24+
// This is not available on other versions... sorry!
25+
}
26+
}
1927

2028
@end

ios/ContextMenuView.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ @implementation ContextMenuView {
2020
UIView *_customView;
2121
}
2222

23+
- (id) init {
24+
self = [super init];
25+
26+
if (@available(iOS 14.0, *)) {
27+
self.contextMenuInteractionEnabled = true;
28+
} else {
29+
// Fallback on earlier versions
30+
}
31+
32+
return self;
33+
}
34+
2335
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex
2436
{
2537
if ([subview.nativeID isEqualToString:@"ContextMenuPreview"]) {

0 commit comments

Comments
 (0)