From 987583b00be723489be4e0fd59f17b81a6221e99 Mon Sep 17 00:00:00 2001 From: Arthur Wang Date: Wed, 8 Jun 2016 18:56:05 +0800 Subject: [PATCH 1/2] introduce a new interface --- ToolTipMenu/ToolTipMenu.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ToolTipMenu/ToolTipMenu.m b/ToolTipMenu/ToolTipMenu.m index 81be73d..e2b2c93 100644 --- a/ToolTipMenu/ToolTipMenu.m +++ b/ToolTipMenu/ToolTipMenu.m @@ -35,4 +35,28 @@ - (dispatch_queue_t)methodQueue [menuCont setMenuVisible:YES animated:YES]; } +RCT_EXPORT_METHOD(showFromRect:(nonnull NSNumber *)reactTag + items: (NSArray *)items + rect: (NSArray *)rectArr) +{ + CGRect rect = CGRectMake([rectArr[0] floatValue], [rectArr[1] floatValue], + [rectArr[2] floatValue], [rectArr[3] floatValue]); + UIView *view = [self.bridge.uiManager viewForReactTag:reactTag]; + NSArray *buttons = items; + NSMutableArray *menuItems = [NSMutableArray array]; + for (NSString *buttonText in buttons) { + NSString *sel = [NSString stringWithFormat:@"magic_%@", buttonText]; + [menuItems addObject:[[UIMenuItem alloc] + initWithTitle:buttonText + action:NSSelectorFromString(sel)]]; + } + [view becomeFirstResponder]; + UIMenuController *menuCont = [UIMenuController sharedMenuController]; + view.superview.frame = rect; + [menuCont setTargetRect:view.frame inView:view.superview]; + menuCont.arrowDirection = UIMenuControllerArrowDown; + menuCont.menuItems = menuItems; + [menuCont setMenuVisible:YES animated:YES]; +} + @end From 5b971041b3e49ed8f1ee4be607b4eba5185cbbe2 Mon Sep 17 00:00:00 2001 From: Arthur Wang Date: Wed, 8 Jun 2016 19:28:39 +0800 Subject: [PATCH 2/2] modify ToolTip.ios.js as well --- ToolTip.ios.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ToolTip.ios.js b/ToolTip.ios.js index fc0b460..a90a75a 100644 --- a/ToolTip.ios.js +++ b/ToolTip.ios.js @@ -25,6 +25,10 @@ var ViewClass = React.createClass({ ToolTipMenu.show(findNodeHandle(this.refs.toolTipText), this.getOptionTexts()); }, + showMenuFromRect: function(x, y, w, h) { + ToolTipMenu.showFromRect(findNodeHandle(this.refs.toolTipText), this.getOptionTexts(), [x, y, w, h]); + }, + getOptionTexts: function() { return this.props.actions.map((option) => option.text); },