Commit 5978aba7 authored by pichillilorenzo's avatar pichillilorenzo

fix hidden attribute, added isHidden() method

parent 57e1a86b
......@@ -12,7 +12,9 @@
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java" />
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" afterPath="$PROJECT_DIR$/example/lib/main.dart" />
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" />
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" />
......@@ -36,8 +38,8 @@
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" />
<state relative-caret-position="570">
<caret line="213" column="67" lean-forward="false" selection-start-line="213" selection-start-column="67" selection-end-line="213" selection-end-column="67" />
<folding>
<element signature="e#814#834#0" expanded="true" />
</folding>
......@@ -48,8 +50,8 @@
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="243">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" />
<state relative-caret-position="330">
<caret line="30" column="6" lean-forward="false" selection-start-line="30" selection-start-column="6" selection-end-line="30" selection-end-column="6" />
<folding />
</state>
</provider>
......@@ -136,8 +138,8 @@
<option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" />
<option value="$PROJECT_DIR$/android/build.gradle" />
<option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/example/lib/main.dart" />
</list>
</option>
......@@ -440,9 +442,9 @@
<window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3258786" sideWeight="0.4973545" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3258786" sideWeight="0.4973545" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32936507" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17798743" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3290735" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
......@@ -829,29 +831,29 @@
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="416">
<caret line="41" column="11" lean-forward="true" selection-start-line="41" selection-start-column="11" selection-end-line="41" selection-end-column="11" />
<first_editor relative-caret-position="280">
<caret line="45" column="17" lean-forward="true" selection-start-line="45" selection-start-column="17" selection-end-line="45" selection-end-column="17" />
<folding>
<marker date="1537620468637" expanded="false" signature="933:1031" ph="..." />
<marker date="1537620468637" expanded="true" signature="1075:1571" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1121:1189" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1233:1300" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1371:1475" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1505:1568" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1698:1763" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1804:2315" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1838:1866" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1917:2313" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1945:2308" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1971:2301" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1999:2082" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2028:2071" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2108:2292" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2143:2281" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="10474:10507" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10626:10658" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10818:10850" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10946:10971" ph="{...}" />
<marker date="1537705565637" expanded="false" signature="933:1031" ph="..." />
<marker date="1537705565637" expanded="true" signature="1075:1453" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1121:1161" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1205:1245" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1316:1377" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1407:1450" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1580:1645" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1686:2197" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1720:1748" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1799:2195" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="1827:2190" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="1853:2183" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="1881:1964" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="1910:1953" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="1990:2174" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="2025:2163" ph="(...)" />
<marker date="1537705565637" expanded="true" signature="10356:10389" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="10508:10540" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="10700:10732" ph="{...}" />
<marker date="1537705565637" expanded="true" signature="10828:10853" ph="{...}" />
</folding>
</first_editor>
<second_editor />
......@@ -860,8 +862,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" />
<state relative-caret-position="570">
<caret line="213" column="67" lean-forward="false" selection-start-line="213" selection-start-column="67" selection-end-line="213" selection-end-column="67" />
<folding>
<element signature="e#814#834#0" expanded="true" />
</folding>
......@@ -870,8 +872,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="243">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" />
<state relative-caret-position="330">
<caret line="30" column="6" lean-forward="false" selection-start-line="30" selection-start-column="6" selection-end-line="30" selection-end-column="6" />
<folding />
</state>
</provider>
......
......@@ -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