Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds arrowDirection prop #17

Merged
merged 6 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A react-native component from displaying tooltip. Uses UIMenuController.

- `actions`: Array of actions `[{text: 'Copy', onPress: () => Clipboard.set(this.someValue) }]`
- `longPress`: Boolean indicating if the tooltip should be showing on longPress, false by default.
- `arrowDirection`: String indicating the direction of the tooltip arrow. Possible values are: `up`, `down`, `left`, and `right`. Default is `down`.

#### Props from TouchableHighlight.propTypes

Expand Down Expand Up @@ -60,6 +61,7 @@ var tooltip = React.createClass({
]}
underlayColor='transparent'
longPress={true}
arrowDirection='down'
style={styles.textinput}
>
<Text>
Expand Down
9 changes: 8 additions & 1 deletion ToolTip.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ var propTypes = {
text: React.PropTypes.string.isRequired,
onPress: React.PropTypes.func,
})),
arrowDirection: React.PropTypes.oneOf(['up', 'down', 'left', 'right']),
longPress: React.PropTypes.bool,
...TouchableHighlight.propTypes,
};

var ViewClass = React.createClass({
getDefaultProps: function() {
return {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use 2 spaces here :)!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fixed!

arrowDirection: 'down'
};
},

showMenu: function() {
ToolTipMenu.show(findNodeHandle(this.refs.toolTipText), this.getOptionTexts());
ToolTipMenu.show(findNodeHandle(this.refs.toolTipText), this.getOptionTexts(), this.props.arrowDirection);
},

getOptionTexts: function() {
Expand Down
14 changes: 12 additions & 2 deletions ToolTipMenu/ToolTipMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ - (dispatch_queue_t)methodQueue
}

RCT_EXPORT_METHOD(show:(nonnull NSNumber *)reactTag
items: (NSArray *)items)
items: (NSArray *)items
arrowDirection: (NSString *)arrowDirection)
{
UIView *view = [self.bridge.uiManager viewForReactTag:reactTag];
NSArray *buttons = items;
Expand All @@ -30,7 +31,16 @@ - (dispatch_queue_t)methodQueue
[view becomeFirstResponder];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:view.frame inView:view.superview];
menuCont.arrowDirection = UIMenuControllerArrowDown;

if([arrowDirection isEqualToString: @"up"]){
menuCont.arrowDirection = UIMenuControllerArrowUp;
}else if ([arrowDirection isEqualToString: @"right"]){
menuCont.arrowDirection = UIMenuControllerArrowRight;
}else if ([arrowDirection isEqualToString: @"left"]) {
menuCont.arrowDirection = UIMenuControllerArrowLeft;
} else {
menuCont.arrowDirection = UIMenuControllerArrowDown;
}
menuCont.menuItems = menuItems;
[menuCont setMenuVisible:YES animated:YES];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-tooltip",
"version": "4.1.0",
"version": "4.1.1",
"description": "A react-native wrapper for showing tooltips",
"main": "ToolTip.ios.js",
"author": {
Expand Down