diff --git a/example/App.js b/example/App.js index 0153bb5..c50c2da 100644 --- a/example/App.js +++ b/example/App.js @@ -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({ @@ -106,7 +106,12 @@ const App = () => { }, ]} previewBackgroundColor="transparent" - preview={}> + preview={ + console.log('TAPPP')}> + + + } + onPreviewPress={() => Alert.alert('Preview Tapped')}> diff --git a/index.d.ts b/index.d.ts index 04e7331..cb877d7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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) => void; + /** + * Handle when the preview is tapped. iOS only. + */ + onPreviewPress?: () => void; /** * Handle when the menu is cancelled and closed */ diff --git a/ios/ContextMenu.m b/ios/ContextMenu.m index e759572..c86f531 100644 --- a/ios/ContextMenu.m +++ b/ios/ContextMenu.m @@ -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) RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL) diff --git a/ios/ContextMenuView.h b/ios/ContextMenuView.h index a6791d9..9456f01 100644 --- a/ios/ContextMenuView.h +++ b/ios/ContextMenuView.h @@ -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* actions; @property (nullable, nonatomic, copy) UIColor* previewBackgroundColor; diff --git a/ios/ContextMenuView.m b/ios/ContextMenuView.m index 0228743..80acda1 100644 --- a/ios/ContextMenuView.m +++ b/ios/ContextMenuView.m @@ -93,6 +93,12 @@ - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willDispl _cancelled = true; } +- (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willPerformPreviewActionForMenuWithConfiguration:(nonnull UIContextMenuConfiguration *)configuration animator:(nonnull id)animator API_AVAILABLE(ios(13.0)) { + if (self.onPreviewPress) { + self.onPreviewPress(@{}); + } +} + - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction willEndForConfiguration:(UIContextMenuConfiguration *)configuration animator:(id)animator API_AVAILABLE(ios(13.0)) { if (_cancelled && self.onCancel) { self.onCancel(@{});