Commit 5978aba7 authored by pichillilorenzo's avatar pichillilorenzo

fix hidden attribute, added isHidden() method

parent 57e1a86b
This diff is collapsed.
......@@ -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");
}
......
......@@ -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();
......
......@@ -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);
......
......@@ -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<Boolean>() {
......
......@@ -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");
}
......@@ -82,11 +80,13 @@ class _MyAppState extends State<MyApp> {
body: new Center(
child: new RaisedButton(onPressed: () {
inAppBrowser.open("https://flutter.io/", options: {
//"hidden": true
//"toolbarTopFixedTitle": "Fixed title",
//"hideUrlBar": true,
//"toolbarTop": false,
//"toolbarBottom": false
});
},
child: Text("Open InAppBrowser")
),
......
......@@ -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)!
......
......@@ -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,7 +179,12 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let browserOptions = InAppBrowserOptions()
browserOptions.parse(options: options)
if webViewController == nil {
if webViewController != nil {
close()
}
else if self.previousStatusBarStyle == -1 {
self.previousStatusBarStyle = UIApplication.shared.statusBarStyle.rawValue
}
if !(self.tmpWindow != nil) {
let frame: CGRect = UIScreen.main.bounds
......@@ -187,43 +195,58 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
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
}
if !browserOptions.hidden {
show()
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)
}
})
}
......@@ -233,19 +256,20 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
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
}
}
......@@ -173,8 +173,13 @@ class InAppBrowser {
return await _channel.invokeMethod('stopLoading');
}
///Check if the Web View of the [InAppBrowser] instance is hidden.
Future<bool> 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<dynamic> injectScriptCode(String source) async {
Future<String> injectScriptCode(String source) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('source', () => source);
return await _channel.invokeMethod('injectScriptCode', args);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment