Skip to content

Commit

Permalink
Merge pull request #85 from naoufal/chaithanyaprathyush-master
Browse files Browse the repository at this point in the history
Bug fixes and Perfomance fixes
  • Loading branch information
koenpunt authored Jul 7, 2018
2 parents 640075e + 8a4d8d0 commit d828e79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 0 additions & 2 deletions SafariViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@

@interface SafariViewManager : RCTEventEmitter <RCTBridgeModule, SFSafariViewControllerDelegate>

@property (nonatomic) SFSafariViewController *safariView;

@end
29 changes: 14 additions & 15 deletions SafariViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@implementation SafariViewManager
{
bool hasListeners;
SFSafariViewController *_safariView;
}

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -39,44 +40,44 @@ - (void)stopObserving
return;
}

NSURL *url = [NSURL URLWithString:args[@"url"]];
NSURL *url = [RCTConvert NSURL:args[@"url"]];
BOOL readerMode = [args[@"readerMode"] boolValue];
UIColor *tintColorString = args[@"tintColor"];
UIColor *barTintColorString = args[@"barTintColor"];
BOOL fromBottom = [args[@"fromBottom"] boolValue];

// Initialize the Safari View
self.safariView = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
self.safariView.delegate = self;
_safariView = [[SFSafariViewController alloc] initWithURL:url entersReaderIfAvailable:readerMode];
_safariView.delegate = self;

// Set tintColor if available
if (tintColorString) {
UIColor *tintColor = [RCTConvert UIColor:tintColorString];
if ([self.safariView respondsToSelector:@selector(setPreferredControlTintColor:)]) {
[self.safariView setPreferredControlTintColor:tintColor];
if ([_safariView respondsToSelector:@selector(setPreferredControlTintColor:)]) {
[_safariView setPreferredControlTintColor:tintColor];
} else {
[self.safariView.view setTintColor:tintColor];
[_safariView.view setTintColor:tintColor];
}
}

// Set barTintColor if available
if (barTintColorString) {
UIColor *barTintColor = [RCTConvert UIColor:barTintColorString];
if ([self.safariView respondsToSelector:@selector(setPreferredBarTintColor:)]) {
[self.safariView setPreferredBarTintColor:barTintColor];
if ([_safariView respondsToSelector:@selector(setPreferredBarTintColor:)]) {
[_safariView setPreferredBarTintColor:barTintColor];
}
}

// Set modal transition style
if (fromBottom) {
self.safariView.modalPresentationStyle = UIModalPresentationOverFullScreen;
_safariView.modalPresentationStyle = UIModalPresentationOverFullScreen;
}

// get the view controller closest to the foreground
UIViewController *ctrl = RCTPresentedViewController();

// Display the Safari View
[ctrl presentViewController:self.safariView animated:YES completion:nil];
[ctrl presentViewController:_safariView animated:YES completion:nil];

if (hasListeners) {
[self sendEventWithName:@"SafariViewOnShow" body:nil];
Expand All @@ -87,7 +88,7 @@ - (void)stopObserving

RCT_EXPORT_METHOD(isAvailable:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
if ([SFSafariViewController class]) {
if (@available(iOS 9.0, *)) {
// SafariView is available
resolve(@YES);
} else {
Expand All @@ -97,17 +98,15 @@ - (void)stopObserving

RCT_EXPORT_METHOD(dismiss)
{
[self safariViewControllerDidFinish:self.safariView];
[_safariView dismissViewControllerAnimated:true completion:nil];
}

-(void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller
{
[controller dismissViewControllerAnimated:true completion:nil];
_safariView = nil;
NSLog(@"[SafariView] SafariView dismissed.");

if (hasListeners) {
[self sendEventWithName:@"SafariViewOnDismiss" body:nil];
}
}

@end

0 comments on commit d828e79

Please sign in to comment.