From 58bbab6ace949c3a01880e98c7c66a54e2322aea Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 30 Oct 2017 13:17:54 +0800 Subject: [PATCH 1/2] Allow closing the in app browser programmatically --- RCTBrowser.h | 4 ++++ RCTBrowser.m | 15 +++++++++++++++ index.ios.js | 3 +++ 3 files changed, 22 insertions(+) diff --git a/RCTBrowser.h b/RCTBrowser.h index e8936a1..e2506a3 100644 --- a/RCTBrowser.h +++ b/RCTBrowser.h @@ -1,6 +1,10 @@ #import "RCTBridgeModule.h" #import "RCTConvert.h" +#import "TOWebViewController.h" + @interface RCTBrowser : NSObject +@property (nonatomic) TOWebViewController *browser; + @end diff --git a/RCTBrowser.m b/RCTBrowser.m index be343de..22ce706 100644 --- a/RCTBrowser.m +++ b/RCTBrowser.m @@ -8,6 +8,14 @@ @implementation RCTBrowser RCT_EXPORT_METHOD(presentUrl:(NSString *)url withOptions:(NSDictionary *)options) { + if ([[options objectForKey:@"deleteAllCookies"] isEqual: @(YES)]) { + NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; + for (NSHTTPCookie *cookie in [storage cookies]) { + [storage deleteCookie:cookie]; + } + [[NSUserDefaults standardUserDefaults] synchronize]; + } + TOWebViewController *webVC = [[TOWebViewController alloc] initWithURLString:url]; [options enumerateKeysAndObjectsUsingBlock:^(NSString* key, id obj, BOOL *stop) { @@ -65,6 +73,13 @@ @implementation RCTBrowser dispatch_async(dispatch_get_main_queue(), ^{ [rootVC presentViewController:nav animated:YES completion: nil]; }); + + self.browser = webVC; +} + +RCT_EXPORT_METHOD(close) { + UIViewController *rootVC = [[UIApplication sharedApplication] keyWindow].rootViewController; + [rootVC dismissViewControllerAnimated:YES completion:nil]; } @end diff --git a/index.ios.js b/index.ios.js index 3f39a41..769ddd0 100644 --- a/index.ios.js +++ b/index.ios.js @@ -12,6 +12,9 @@ var RCTBrowserExport = { open: function(url, options={}) { Browser.presentUrl(url, options); }, + close: function (){ + Browser.close(); + } }; module.exports = RCTBrowserExport; From 4070a3bca4e51577e96eddc375e48a300ef21aff Mon Sep 17 00:00:00 2001 From: alex621 Date: Mon, 30 Oct 2017 13:29:00 +0800 Subject: [PATCH 2/2] Added description for the extended function this fork provides --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 980a375..2043f35 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # react-native-browser A full-featured web browser module for React Native apps, based on the awesome [TOWebViewController](https://github.com/TimOliver/TOWebViewController) +***Added a close() method to close the browser programatically*** + ![TOWebViewController](screenshot.jpg) ### Installation