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
9 changes: 7 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { SafeAreaView, View, StyleSheet, Platform } from 'react-native';
import { SafeAreaView, View, StyleSheet, Platform, TouchableOpacity, Alert } from 'react-native';
import ContextMenu from 'react-native-context-menu-view';

const Icons = Platform.select({
Expand Down Expand Up @@ -106,7 +106,12 @@ const App = () => {
},
]}
previewBackgroundColor="transparent"
preview={<View style={[styles.rectangle, { backgroundColor: 'green' }]} />}>
preview={
<TouchableOpacity onPress={() => console.log('TAPPP')}>
<View style={[styles.rectangle, { backgroundColor: 'green' }]} />
</TouchableOpacity>
}
onPreviewPress={() => Alert.alert('Preview Tapped')}>
<View style={[styles.rectangle, { backgroundColor: 'red' }]} />
</ContextMenu>
</SafeAreaView>
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export interface ContextMenuProps extends ViewProps {
* Handle when an action is triggered and the menu is closed. The name of the selected action will be passed in the event.
*/
onPress?: (e: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>) => void;
/**
* Handle when the preview is tapped. iOS only.
*/
onPreviewPress?: () => void;
/**
* Handle when the menu is cancelled and closed
*/
Expand Down
1 change: 1 addition & 0 deletions ios/ContextMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ - (UIView *) view {

RCT_EXPORT_VIEW_PROPERTY(title, NSString)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPreviewPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onCancel, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(actions, NSArray<ContextMenuAction>)
RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL)
Expand Down
1 change: 1 addition & 0 deletions ios/ContextMenuView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@property (nonnull, nonatomic, copy) NSString* title;
@property (nullable, nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nullable, nonatomic, copy) RCTBubblingEventBlock onPreviewPress;
@property (nullable, nonatomic, copy) RCTBubblingEventBlock onCancel;
@property (nullable, nonatomic, copy) NSArray<ContextMenuAction*>* actions;
@property (nullable, nonatomic, copy) UIColor* previewBackgroundColor;
Expand Down
6 changes: 6 additions & 0 deletions ios/ContextMenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willDispl
_cancelled = true;
}

- (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willPerformPreviewActionForMenuWithConfiguration:(nonnull UIContextMenuConfiguration *)configuration animator:(nonnull id<UIContextMenuInteractionCommitAnimating>)animator API_AVAILABLE(ios(13.0)) {
if (self.onPreviewPress) {
self.onPreviewPress(@{});
}
}

- (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willEndForConfiguration:(UIContextMenuConfiguration *)configuration animator:(id<UIContextMenuInteractionAnimating>)animator API_AVAILABLE(ios(13.0)) {
if (_cancelled && self.onCancel) {
self.onCancel(@{});
Expand Down