From c89b5614209f93d0fc012914d34de213e2f2e8c6 Mon Sep 17 00:00:00 2001 From: Pranav Raj Singh Chauhan Date: Fri, 2 Mar 2018 13:16:09 +0530 Subject: [PATCH] - added onHide callback support for iOS --- Example/ios/Example.xcodeproj/project.pbxproj | 2 ++ RNTooltips.js | 14 ++++++-- ios/RNTooltips.m | 33 +++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Example/ios/Example.xcodeproj/project.pbxproj b/Example/ios/Example.xcodeproj/project.pbxproj index 8184d1b..6ecb56b 100644 --- a/Example/ios/Example.xcodeproj/project.pbxproj +++ b/Example/ios/Example.xcodeproj/project.pbxproj @@ -1012,6 +1012,7 @@ "-lc++", ); PRODUCT_NAME = Example; + TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -1033,6 +1034,7 @@ "-lc++", ); PRODUCT_NAME = Example; + TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; diff --git a/RNTooltips.js b/RNTooltips.js index cfad377..aa1a9e7 100644 --- a/RNTooltips.js +++ b/RNTooltips.js @@ -56,7 +56,13 @@ class Tooltips extends Component { props.shadow = Tooltips.defaultProps.shadow; } - RNTooltips.Show(ref, props); + RNTooltips.Show( + ref, + props, + () => { + props.onHide && props.onHide() + } + ); } componentDidUpdate() { @@ -73,7 +79,8 @@ class Tooltips extends Component { textColor: this.props.textColor, textSize: this.props.textSize, gravity: this.props.gravity, - shadow: this.props.shadow + shadow: this.props.shadow, + onHide: this.props.onHide }); } } @@ -99,7 +106,8 @@ Tooltips.propTypes = { gravity: PropTypes.number, shadow: PropTypes.bool, visible: PropTypes.bool, - reference: PropTypes.object + reference: PropTypes.object, + onHide: PropTypes.func }; Tooltips.defaultProps = { diff --git a/ios/RNTooltips.m b/ios/RNTooltips.m index 1c42bad..749b0c4 100644 --- a/ios/RNTooltips.m +++ b/ios/RNTooltips.m @@ -1,6 +1,22 @@ #import "RNTooltips.h" + + +@interface TooltipDelegate : NSObject + +@property (nonatomic, strong) RCTResponseSenderBlock onHide; + +@end + +@implementation TooltipDelegate +- (void)tooltipDidDismiss:(SexyTooltip *)tooltip { + _onHide(@[]); +} + +@end + + @implementation RNTooltips @synthesize bridge = _bridge; @@ -12,7 +28,7 @@ - (dispatch_queue_t)methodQueue RCT_EXPORT_MODULE() -RCT_EXPORT_METHOD(Show:(nonnull NSNumber *)view props:(NSDictionary *)props) +RCT_EXPORT_METHOD(Show:(nonnull NSNumber *)view props:(NSDictionary *)props onHide:(RCTResponseSenderBlock)onHide) { UIView *target = [self.bridge.uiManager viewForReactTag: view]; @@ -34,25 +50,30 @@ - (dispatch_queue_t)methodQueue [attributes addAttribute:NSFontAttributeName value: [UIFont systemFontOfSize: [textSize floatValue]] range:NSMakeRange(0,text.length)]; SexyTooltip *toolTip = [[SexyTooltip alloc] initWithAttributedString: attributes]; + + TooltipDelegate *delegate = [[TooltipDelegate alloc] init]; + delegate.onHide = onHide; + [toolTip setDelegate: delegate]; + toolTip.color = [RNTooltips colorFromHexCode: tintColor]; toolTip.cornerRadius = [corner floatValue]; toolTip.dismissesOnTap = [clickToHide boolValue]; toolTip.padding = UIEdgeInsetsMake(6, 8, 6, 8); - + if ([shadow boolValue]) { toolTip.hasShadow = YES; } if ([autoHide boolValue]) { - dispatch_async(dispatch_get_main_queue(), ^{ - [toolTip dismissInTimeInterval:(NSTimeInterval) [duration floatValue] animated: YES]; - // Timer here - }); +// dispatch_async(dispatch_get_main_queue(), ^{ + [toolTip dismissInTimeInterval:(NSTimeInterval) [duration floatValue] animated: YES]; +// }); } [toolTip presentFromView:target animated:YES]; } + + (UIColor *) colorFromHexCode:(NSString *)hexString { NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""]; if([cleanString length] == 3) {