Skip to content

Commit

Permalink
- added onHide callback support for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
prscms committed Mar 2, 2018
1 parent 2fe0673 commit c89b561
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Example/ios/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@
"-lc++",
);
PRODUCT_NAME = Example;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand All @@ -1033,6 +1034,7 @@
"-lc++",
);
PRODUCT_NAME = Example;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
14 changes: 11 additions & 3 deletions RNTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
});
}
}
Expand All @@ -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 = {
Expand Down
33 changes: 27 additions & 6 deletions ios/RNTooltips.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@

#import "RNTooltips.h"



@interface TooltipDelegate : NSObject <SexyTooltipDelegate>

@property (nonatomic, strong) RCTResponseSenderBlock onHide;

@end

@implementation TooltipDelegate
- (void)tooltipDidDismiss:(SexyTooltip *)tooltip {
_onHide(@[]);
}

@end


@implementation RNTooltips

@synthesize bridge = _bridge;
Expand All @@ -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];

Expand All @@ -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) {
Expand Down

0 comments on commit c89b561

Please sign in to comment.