diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 582e23dc..75ebc0be 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -12,7 +12,9 @@
+
+
@@ -36,8 +38,8 @@
-
-
+
+
@@ -48,8 +50,8 @@
-
-
+
+
@@ -136,8 +138,8 @@
-
+
@@ -440,9 +442,9 @@
-
+
-
+
@@ -829,29 +831,29 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -860,8 +862,8 @@
-
-
+
+
@@ -870,8 +872,8 @@
-
-
+
+
diff --git a/README.md b/README.md
index 73645372..8352d77d 100644
--- a/README.md
+++ b/README.md
@@ -29,25 +29,21 @@ class MyInAppBrowser extends InAppBrowser {
@override
void onLoadStart(String url) {
- super.onLoadStart(url);
print("\n\nStarted $url\n\n");
}
@override
void onLoadStop(String url) {
- super.onLoadStop(url);
print("\n\nStopped $url\n\n");
}
@override
void onLoadError(String url, int code, String message) {
- super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n");
}
@override
void onExit() {
- super.onExit();
print("\n\nBrowser closed!\n\n");
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
index 9a722d30..a83353dd 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
@@ -195,13 +195,16 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "canGoForward":
result.success(canGoForward());
break;
- case "isLoading":
- result.success(isLoading());
- break;
case "stopLoading":
stopLoading();
result.success(true);
break;
+ case "isLoading":
+ result.success(isLoading());
+ break;
+ case "isHidden":
+ result.success(isHidden());
+ break;
default:
result.notImplemented();
}
@@ -343,7 +346,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
}
// If the current app package isn't a target for this URL, then use
// the normal launch behavior
- if (hasCurrentPackage == false || targetIntents.size() == 0) {
+ if (!hasCurrentPackage || targetIntents.size() == 0) {
activity.startActivity(intent);
}
// If there's only one possible intent, launch it directly
@@ -400,6 +403,12 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
return false;
}
+ public boolean isHidden() {
+ if (webViewActivity != null)
+ return webViewActivity.isHidden;
+ return false;
+ }
+
public void stopLoading() {
if (webViewActivity != null)
webViewActivity.stopLoading();
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
index fc243720..b2b2ef4d 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
@@ -28,6 +28,8 @@ public class InAppBrowserWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
+ //return true;
+
if (url.startsWith(WebView.SCHEME_TEL)) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL);
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
index 07904515..a72cb82f 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java
@@ -7,6 +7,7 @@ import android.os.Build;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
@@ -34,10 +35,12 @@ public class WebViewActivity extends AppCompatActivity {
InAppBrowserOptions options;
ProgressBar progressBar;
public boolean isLoading = false;
+ public boolean isHidden = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
setContentView(R.layout.activity_web_view);
webView = findViewById(R.id.webView);
@@ -273,12 +276,21 @@ public class WebViewActivity extends AppCompatActivity {
}
public void hide() {
- if (webView != null)
- webView.setVisibility(View.INVISIBLE);
+ isHidden = true;
+ Intent openMainActivity= new Intent(this, InAppBrowserFlutterPlugin.registrar.activity().getClass());
+ openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ startActivityIfNeeded(openMainActivity, 0);
}
public void show() {
+ isHidden = false;
+ Intent openMainActivity= new Intent(InAppBrowserFlutterPlugin.registrar.activity(), WebViewActivity.class);
+ openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
+ startActivityIfNeeded(openMainActivity, 0);
+ }
+
+ public void stopLoading(){
if (webView != null)
- webView.setVisibility(View.VISIBLE);
+ webView.stopLoading();
}
public boolean isLoading() {
@@ -287,11 +299,6 @@ public class WebViewActivity extends AppCompatActivity {
return false;
}
- public void stopLoading(){
- if (webView != null)
- webView.stopLoading();
- }
-
private void clearCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeAllCookies(new ValueCallback() {
diff --git a/example/lib/main.dart b/example/lib/main.dart
index 121a1403..3d4ce3c6 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -5,30 +5,30 @@ import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class MyInAppBrowser extends InAppBrowser {
@override
- void onLoadStart(String url) {
- super.onLoadStart(url);
+ Future onLoadStart(String url) async {
print("\n\nStarted $url\n\n");
+ //print("\n\n ${await this.isHidden()} \n\n");
}
@override
- void onLoadStop(String url) async {
- super.onLoadStop(url);
+ Future onLoadStop(String url) async {
print("\n\nStopped $url\n\n");
- print(await this.injectScriptCode("document.body.innerHTML"));
- print(await this.injectScriptCode("3"));
- print(await this.injectScriptCode("""
- function asd (a,b) {
- return a+b;
- };
- asd(3,5);
- """));
- print(await this.injectScriptCode("""
- ["3",56,"sdf"];
- """));
- print(await this.injectScriptCode("""
- var x = {"as":4, "dfdfg": 6};
- x;
- """));
+// print(await this.injectScriptCode("document.body.innerHTML"));
+// print(await this.injectScriptCode("3"));
+// print(await this.injectScriptCode("""
+// function asd (a,b) {
+// return a+b;
+// };
+// asd(3,5);
+// """));
+// print(await this.injectScriptCode("""
+// ["3",56,"sdf"];
+// """));
+// print(await this.injectScriptCode("""
+// var x = {"as":4, "dfdfg": 6};
+// x;
+// """));
+ //print("\n\n ${await this.isHidden()} \n\n");
/*this.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js");
this.injectScriptCode("""
\$( "body" ).html( "Next Step..." )
@@ -44,13 +44,11 @@ class MyInAppBrowser extends InAppBrowser {
@override
void onLoadError(String url, int code, String message) {
- super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n");
}
@override
void onExit() {
- super.onExit();
print("\n\nBrowser closed!\n\n");
}
@@ -81,12 +79,14 @@ class _MyAppState extends State {
),
body: new Center(
child: new RaisedButton(onPressed: () {
- inAppBrowser.open("https://flutter.io/", options: {
- //"toolbarTopFixedTitle": "Fixed title",
- //"hideUrlBar": true,
- //"toolbarTop": false,
- //"toolbarBottom": false
- });
+ inAppBrowser.open("https://flutter.io/", options: {
+ //"hidden": true
+ //"toolbarTopFixedTitle": "Fixed title",
+ //"hideUrlBar": true,
+ //"toolbarTop": false,
+ //"toolbarBottom": false
+ });
+
},
child: Text("Open InAppBrowser")
),
diff --git a/ios/Classes/InAppBrowserWebViewController.swift b/ios/Classes/InAppBrowserWebViewController.swift
index 56528d35..81b6d297 100644
--- a/ios/Classes/InAppBrowserWebViewController.swift
+++ b/ios/Classes/InAppBrowserWebViewController.swift
@@ -79,6 +79,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
var tmpWindow: UIWindow?
var browserOptions: InAppBrowserOptions?
var initHeaders: [String: String]?
+ var isHidden = false
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
diff --git a/ios/Classes/SwiftFlutterPlugin.swift b/ios/Classes/SwiftFlutterPlugin.swift
index b6ae5375..e624f990 100644
--- a/ios/Classes/SwiftFlutterPlugin.swift
+++ b/ios/Classes/SwiftFlutterPlugin.swift
@@ -87,6 +87,9 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
self.webViewController?.webView.stopLoading()
result(true)
break
+ case "isHidden":
+ result((self.webViewController?.isHidden ?? false) == true)
+ break
case "injectScriptCode":
self.injectScriptCode(arguments: arguments!, result: result)
break
@@ -176,76 +179,97 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let browserOptions = InAppBrowserOptions()
browserOptions.parse(options: options)
- if webViewController == nil {
-
- if !(self.tmpWindow != nil) {
- let frame: CGRect = UIScreen.main.bounds
- self.tmpWindow = UIWindow(frame: frame)
- }
-
- let storyboard = UIStoryboard(name: WEBVIEW_STORYBOARD, bundle: nil)
- let vc = storyboard.instantiateViewController(withIdentifier: WEBVIEW_STORYBOARD_CONTROLLER_ID)
- webViewController = vc as? InAppBrowserWebViewController
- webViewController?.browserOptions = browserOptions
- webViewController?.tmpWindow = tmpWindow
- webViewController?.currentURL = url
- webViewController?.initHeaders = headers
- webViewController?.navigationDelegate = self
+ if webViewController != nil {
+ close()
+ }
+ else if self.previousStatusBarStyle == -1 {
+ self.previousStatusBarStyle = UIApplication.shared.statusBarStyle.rawValue
}
- if !browserOptions.hidden {
- show()
+ if !(self.tmpWindow != nil) {
+ let frame: CGRect = UIScreen.main.bounds
+ self.tmpWindow = UIWindow(frame: frame)
+ }
+
+ let storyboard = UIStoryboard(name: WEBVIEW_STORYBOARD, bundle: nil)
+ let vc = storyboard.instantiateViewController(withIdentifier: WEBVIEW_STORYBOARD_CONTROLLER_ID)
+ webViewController = vc as? InAppBrowserWebViewController
+ webViewController?.browserOptions = browserOptions
+ webViewController?.isHidden = browserOptions.hidden
+ webViewController?.tmpWindow = tmpWindow
+ webViewController?.currentURL = url
+ webViewController?.initHeaders = headers
+ webViewController?.navigationDelegate = self
+
+ let tmpController = UIViewController()
+ let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel
+ self.tmpWindow?.rootViewController = tmpController
+ self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1)
+ self.tmpWindow?.makeKeyAndVisible()
+ if browserOptions.hidden {
+ webViewController!.view.isHidden = true
+ tmpController.present(self.webViewController!, animated: false, completion: {() -> Void in
+ if self.previousStatusBarStyle != -1 {
+ UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
+ }
+ })
+ if self.previousStatusBarStyle != -1 {
+ UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
+ }
+ webViewController?.presentingViewController?.dismiss(animated: false, completion: {() -> Void in
+ self.tmpWindow?.windowLevel = 0.0
+ UIApplication.shared.delegate?.window??.makeKeyAndVisible()
+ if self.previousStatusBarStyle != -1 {
+ UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
+ }
+ })
+ }
+ else {
+ tmpController.present(webViewController!, animated: true, completion: nil)
}
}
public func show() {
+
if webViewController == nil {
- print("Tried to show IAB after it was closed.")
- return
- }
- if previousStatusBarStyle != -1 {
- print("Tried to show IAB while already shown")
+ print("Tried to hide IAB after it was closed.")
return
}
- weak var weakSelf: SwiftFlutterPlugin? = self
+ self.webViewController?.isHidden = false
+ self.webViewController!.view.isHidden = false
// Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in
- if weakSelf?.webViewController != nil {
- if !(self.tmpWindow != nil) {
- let frame: CGRect = UIScreen.main.bounds
- self.tmpWindow = UIWindow(frame: frame)
- }
- let tmpController = UIViewController()
+ if self.webViewController != nil {
let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel
- self.tmpWindow?.rootViewController = tmpController
self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1)
self.tmpWindow?.makeKeyAndVisible()
-
- tmpController.present(self.webViewController!, animated: true, completion: nil)
+ UIApplication.shared.delegate?.window??.makeKeyAndVisible()
+ self.tmpWindow?.rootViewController?.present(self.webViewController!, animated: true, completion: nil)
}
})
}
-
+
public func hide() {
if webViewController == nil {
print("Tried to hide IAB after it was closed.")
return
}
- if previousStatusBarStyle == -1 {
- print("Tried to hide IAB while already hidden")
- return
+
+ if self.webViewController != nil {
+ self.webViewController?.isHidden = true
}
- previousStatusBarStyle = UIApplication.shared.statusBarStyle.rawValue
// Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in
if self.webViewController != nil {
- self.previousStatusBarStyle = -1
self.webViewController?.presentingViewController?.dismiss(animated: true, completion: {() -> Void in
self.tmpWindow?.windowLevel = 0.0
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
+ if self.previousStatusBarStyle != -1 {
+ UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
+ }
})
}
})
@@ -345,8 +369,6 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: previousStatusBarStyle)!
}
- previousStatusBarStyle = -1
- // this value was reset before reapplying it. caused statusbar to stay black on ios7
}
}
diff --git a/lib/flutter_inappbrowser.dart b/lib/flutter_inappbrowser.dart
index 5a76edad..fbc01326 100644
--- a/lib/flutter_inappbrowser.dart
+++ b/lib/flutter_inappbrowser.dart
@@ -173,8 +173,13 @@ class InAppBrowser {
return await _channel.invokeMethod('stopLoading');
}
+ ///Check if the Web View of the [InAppBrowser] instance is hidden.
+ Future isHidden() async {
+ return await _channel.invokeMethod('isHidden');
+ }
+
///Injects JavaScript code into the [InAppBrowser] window. (Only available when the target is set to `_blank` or to `_self`)
- Future injectScriptCode(String source) async {
+ Future injectScriptCode(String source) async {
Map args = {};
args.putIfAbsent('source', () => source);
return await _channel.invokeMethod('injectScriptCode', args);