Skip to content

Commit

Permalink
Merge pull request #9 from OutSystems/fix/RNMT-3324/does-not-open-in-…
Browse files Browse the repository at this point in the history
…ios13

RNMT-3324  [InAppBrowser] In app browser doesn't open in iOS 13
  • Loading branch information
usernuno authored Oct 4, 2019
2 parents 9fd7303 + 58adfa8 commit 4af3146
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ addons:
env:
global:
- SAUCE_USERNAME=snay
- TRAVIS_NODE_VERSION=6
- TRAVIS_NODE_VERSION=8
- ANDROID_API_LEVEL=28
- ANDROID_BUILD_TOOLS_VERSION=28.0.3

language: node_js
node_js: 6
node_js: 8

# yaml anchor/alias: https://medium.com/@tommyvn/travis-yml-dry-with-anchors-8b6a3ac1b027

Expand Down
2 changes: 1 addition & 1 deletion src/ios/CDVUIInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ -(void)createIframeBridge

- (void)injectDeferredObject:(NSString*)source withWrapper:(NSString*)jsWrapper
{
[self createIframeBridge];
if (jsWrapper != nil) {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@[source] options:0 error:nil];
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
Expand Down Expand Up @@ -569,7 +570,6 @@ - (void)webViewDidStartLoad:(UIWebView*)theWebView

- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
[self createIframeBridge];
if (self.callbackId != nil) {
// TODO: It would be more useful to return the URL the page is actually on (e.g. if it's been redirected).
NSString* url = [self.inAppBrowserViewController.currentURL absoluteString];
Expand Down
2 changes: 2 additions & 0 deletions src/ios/CDVWKInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
@class CDVWKInAppBrowserViewController;

@interface CDVWKInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;

@private
NSString* _beforeload;
BOOL _waitForBeforeload;
Expand Down
37 changes: 25 additions & 12 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ - (void)close:(CDVInvokedUrlCommand*)command
NSLog(@"IAB.close() called but it was already closed.");
return;
}

// Things are cleaned up in browserExit.
[self.inAppBrowserViewController close];
}
Expand Down Expand Up @@ -279,7 +280,9 @@ - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
_waitForBeforeload = ![_beforeload isEqualToString:@""];

[self.inAppBrowserViewController navigateTo:url];
[self show:nil withNoAnimate:browserOptions.hidden];
if (!browserOptions.hidden) {
[self show:nil withNoAnimate:browserOptions.hidden];
}
}

- (void)show:(CDVInvokedUrlCommand*)command{
Expand Down Expand Up @@ -318,19 +321,21 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate
dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) {
float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
CGRect frame = [[UIScreen mainScreen] bounds];
if(initHidden && osVersion < 11){
frame.origin.x = -10000;
__strong __typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf->tmpWindow) {
CGRect frame = [[UIScreen mainScreen] bounds];
if(initHidden && osVersion < 11){
frame.origin.x = -10000;
}
strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
}

UIWindow *tmpWindow = [[UIWindow alloc] initWithFrame:frame];
UIViewController *tmpController = [[UIViewController alloc] init];
[tmpWindow setRootViewController:tmpController];
[tmpWindow setWindowLevel:UIWindowLevelNormal];

[strongSelf->tmpWindow setRootViewController:tmpController];
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];

if(!initHidden || osVersion < 11){
[tmpWindow makeKeyAndVisible];
[self->tmpWindow makeKeyAndVisible];
}
[tmpController presentViewController:nav animated:!noAnimate completion:nil];
}
Expand All @@ -339,6 +344,10 @@ - (void)show:(CDVInvokedUrlCommand*)command withNoAnimate:(BOOL)noAnimate

- (void)hide:(CDVInvokedUrlCommand*)command
{
// Set tmpWindow to hidden to make main webview responsive to touch again
// https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
self->tmpWindow.hidden = YES;

if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to hide IAB after it was closed.");
return;
Expand Down Expand Up @@ -694,6 +703,10 @@ - (void)browserExit
// Set navigationDelegate to nil to ensure no callbacks are received from it.
self.inAppBrowserViewController.navigationDelegate = nil;
self.inAppBrowserViewController = nil;

// Set tmpWindow to hidden to make main webview responsive to touch again
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
self->tmpWindow.hidden = YES;

if (IsAtLeastiOSVersion(@"7.0")) {
if (_previousStatusBarStyle != -1) {
Expand Down Expand Up @@ -790,7 +803,7 @@ - (void)createViews

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)) {
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
#endif

Expand Down

0 comments on commit 4af3146

Please sign in to comment.