Commit 5978aba7 authored by pichillilorenzo's avatar pichillilorenzo

fix hidden attribute, added isHidden() method

parent 57e1a86b
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment=""> <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$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" /> <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/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$/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/InAppBrowserWebViewController.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" />
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" /> <change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" />
...@@ -36,8 +38,8 @@ ...@@ -36,8 +38,8 @@
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false"> <file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"> <entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270"> <state relative-caret-position="570">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" /> <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> <folding>
<element signature="e#814#834#0" expanded="true" /> <element signature="e#814#834#0" expanded="true" />
</folding> </folding>
...@@ -48,8 +50,8 @@ ...@@ -48,8 +50,8 @@
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true"> <file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart"> <entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="243"> <state relative-caret-position="330">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" /> <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 /> <folding />
</state> </state>
</provider> </provider>
...@@ -136,8 +138,8 @@ ...@@ -136,8 +138,8 @@
<option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" /> <option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" />
<option value="$PROJECT_DIR$/android/build.gradle" /> <option value="$PROJECT_DIR$/android/build.gradle" />
<option value="$PROJECT_DIR$/pubspec.yaml" /> <option value="$PROJECT_DIR$/pubspec.yaml" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/README.md" /> <option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
<option value="$PROJECT_DIR$/example/lib/main.dart" /> <option value="$PROJECT_DIR$/example/lib/main.dart" />
</list> </list>
</option> </option>
...@@ -440,9 +442,9 @@ ...@@ -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="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="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="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="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="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="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" /> <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 @@ ...@@ -829,29 +831,29 @@
<entry file="file://$PROJECT_DIR$/README.md"> <entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]"> <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT"> <state split_layout="SPLIT">
<first_editor relative-caret-position="416"> <first_editor relative-caret-position="280">
<caret line="41" column="11" lean-forward="true" selection-start-line="41" selection-start-column="11" selection-end-line="41" selection-end-column="11" /> <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> <folding>
<marker date="1537620468637" expanded="false" signature="933:1031" ph="..." /> <marker date="1537705565637" expanded="false" signature="933:1031" ph="..." />
<marker date="1537620468637" expanded="true" signature="1075:1571" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1075:1453" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1121:1189" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1121:1161" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1233:1300" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1205:1245" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1371:1475" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1316:1377" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1505:1568" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1407:1450" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1698:1763" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1580:1645" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1804:2315" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1686:2197" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1838:1866" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1720:1748" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1917:2313" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="1799:2195" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="1945:2308" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="1827:2190" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1971:2301" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="1853:2183" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="1999:2082" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="1881:1964" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2028:2071" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="1910:1953" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2108:2292" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="1990:2174" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="2143:2281" ph="(...)" /> <marker date="1537705565637" expanded="true" signature="2025:2163" ph="(...)" />
<marker date="1537620468637" expanded="true" signature="10474:10507" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="10356:10389" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10626:10658" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="10508:10540" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10818:10850" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="10700:10732" ph="{...}" />
<marker date="1537620468637" expanded="true" signature="10946:10971" ph="{...}" /> <marker date="1537705565637" expanded="true" signature="10828:10853" ph="{...}" />
</folding> </folding>
</first_editor> </first_editor>
<second_editor /> <second_editor />
...@@ -860,8 +862,8 @@ ...@@ -860,8 +862,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"> <entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270"> <state relative-caret-position="570">
<caret line="37" column="27" lean-forward="false" selection-start-line="37" selection-start-column="27" selection-end-line="37" selection-end-column="27" /> <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> <folding>
<element signature="e#814#834#0" expanded="true" /> <element signature="e#814#834#0" expanded="true" />
</folding> </folding>
...@@ -870,8 +872,8 @@ ...@@ -870,8 +872,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/lib/main.dart"> <entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="243"> <state relative-caret-position="330">
<caret line="20" column="19" lean-forward="true" selection-start-line="20" selection-start-column="19" selection-end-line="20" selection-end-column="19" /> <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 /> <folding />
</state> </state>
</provider> </provider>
......
...@@ -29,25 +29,21 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -29,25 +29,21 @@ class MyInAppBrowser extends InAppBrowser {
@override @override
void onLoadStart(String url) { void onLoadStart(String url) {
super.onLoadStart(url);
print("\n\nStarted $url\n\n"); print("\n\nStarted $url\n\n");
} }
@override @override
void onLoadStop(String url) { void onLoadStop(String url) {
super.onLoadStop(url);
print("\n\nStopped $url\n\n"); print("\n\nStopped $url\n\n");
} }
@override @override
void onLoadError(String url, int code, String message) { void onLoadError(String url, int code, String message) {
super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n"); print("\n\nCan't load $url.. Error: $message\n\n");
} }
@override @override
void onExit() { void onExit() {
super.onExit();
print("\n\nBrowser closed!\n\n"); print("\n\nBrowser closed!\n\n");
} }
......
...@@ -195,13 +195,16 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -195,13 +195,16 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "canGoForward": case "canGoForward":
result.success(canGoForward()); result.success(canGoForward());
break; break;
case "isLoading":
result.success(isLoading());
break;
case "stopLoading": case "stopLoading":
stopLoading(); stopLoading();
result.success(true); result.success(true);
break; break;
case "isLoading":
result.success(isLoading());
break;
case "isHidden":
result.success(isHidden());
break;
default: default:
result.notImplemented(); result.notImplemented();
} }
...@@ -343,7 +346,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -343,7 +346,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
} }
// If the current app package isn't a target for this URL, then use // If the current app package isn't a target for this URL, then use
// the normal launch behavior // the normal launch behavior
if (hasCurrentPackage == false || targetIntents.size() == 0) { if (!hasCurrentPackage || targetIntents.size() == 0) {
activity.startActivity(intent); activity.startActivity(intent);
} }
// If there's only one possible intent, launch it directly // If there's only one possible intent, launch it directly
...@@ -400,6 +403,12 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -400,6 +403,12 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
return false; return false;
} }
public boolean isHidden() {
if (webViewActivity != null)
return webViewActivity.isHidden;
return false;
}
public void stopLoading() { public void stopLoading() {
if (webViewActivity != null) if (webViewActivity != null)
webViewActivity.stopLoading(); webViewActivity.stopLoading();
......
...@@ -28,6 +28,8 @@ public class InAppBrowserWebViewClient extends WebViewClient { ...@@ -28,6 +28,8 @@ public class InAppBrowserWebViewClient extends WebViewClient {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) { public boolean shouldOverrideUrlLoading(WebView webView, String url) {
//return true;
if (url.startsWith(WebView.SCHEME_TEL)) { if (url.startsWith(WebView.SCHEME_TEL)) {
try { try {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
......
...@@ -7,6 +7,7 @@ import android.os.Build; ...@@ -7,6 +7,7 @@ import android.os.Build;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
...@@ -34,10 +35,12 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -34,10 +35,12 @@ public class WebViewActivity extends AppCompatActivity {
InAppBrowserOptions options; InAppBrowserOptions options;
ProgressBar progressBar; ProgressBar progressBar;
public boolean isLoading = false; public boolean isLoading = false;
public boolean isHidden = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view); setContentView(R.layout.activity_web_view);
webView = findViewById(R.id.webView); webView = findViewById(R.id.webView);
...@@ -273,12 +276,21 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -273,12 +276,21 @@ public class WebViewActivity extends AppCompatActivity {
} }
public void hide() { public void hide() {
if (webView != null) isHidden = true;
webView.setVisibility(View.INVISIBLE); Intent openMainActivity= new Intent(this, InAppBrowserFlutterPlugin.registrar.activity().getClass());
openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openMainActivity, 0);
} }
public void show() { 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) if (webView != null)
webView.setVisibility(View.VISIBLE); webView.stopLoading();
} }
public boolean isLoading() { public boolean isLoading() {
...@@ -287,11 +299,6 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -287,11 +299,6 @@ public class WebViewActivity extends AppCompatActivity {
return false; return false;
} }
public void stopLoading(){
if (webView != null)
webView.stopLoading();
}
private void clearCookies() { private void clearCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() { CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
......
...@@ -5,30 +5,30 @@ import 'package:flutter_inappbrowser/flutter_inappbrowser.dart'; ...@@ -5,30 +5,30 @@ import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class MyInAppBrowser extends InAppBrowser { class MyInAppBrowser extends InAppBrowser {
@override @override
void onLoadStart(String url) { Future onLoadStart(String url) async {
super.onLoadStart(url);
print("\n\nStarted $url\n\n"); print("\n\nStarted $url\n\n");
//print("\n\n ${await this.isHidden()} \n\n");
} }
@override @override
void onLoadStop(String url) async { Future onLoadStop(String url) async {
super.onLoadStop(url);
print("\n\nStopped $url\n\n"); print("\n\nStopped $url\n\n");
print(await this.injectScriptCode("document.body.innerHTML")); // print(await this.injectScriptCode("document.body.innerHTML"));
print(await this.injectScriptCode("3")); // print(await this.injectScriptCode("3"));
print(await this.injectScriptCode(""" // print(await this.injectScriptCode("""
function asd (a,b) { // function asd (a,b) {
return a+b; // return a+b;
}; // };
asd(3,5); // asd(3,5);
""")); // """));
print(await this.injectScriptCode(""" // print(await this.injectScriptCode("""
["3",56,"sdf"]; // ["3",56,"sdf"];
""")); // """));
print(await this.injectScriptCode(""" // print(await this.injectScriptCode("""
var x = {"as":4, "dfdfg": 6}; // var x = {"as":4, "dfdfg": 6};
x; // x;
""")); // """));
//print("\n\n ${await this.isHidden()} \n\n");
/*this.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js"); /*this.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js");
this.injectScriptCode(""" this.injectScriptCode("""
\$( "body" ).html( "Next Step..." ) \$( "body" ).html( "Next Step..." )
...@@ -44,13 +44,11 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -44,13 +44,11 @@ class MyInAppBrowser extends InAppBrowser {
@override @override
void onLoadError(String url, int code, String message) { void onLoadError(String url, int code, String message) {
super.onLoadError(url, code, message);
print("\n\nCan't load $url.. Error: $message\n\n"); print("\n\nCan't load $url.. Error: $message\n\n");
} }
@override @override
void onExit() { void onExit() {
super.onExit();
print("\n\nBrowser closed!\n\n"); print("\n\nBrowser closed!\n\n");
} }
...@@ -81,12 +79,14 @@ class _MyAppState extends State<MyApp> { ...@@ -81,12 +79,14 @@ class _MyAppState extends State<MyApp> {
), ),
body: new Center( body: new Center(
child: new RaisedButton(onPressed: () { child: new RaisedButton(onPressed: () {
inAppBrowser.open("https://flutter.io/", options: { inAppBrowser.open("https://flutter.io/", options: {
//"toolbarTopFixedTitle": "Fixed title", //"hidden": true
//"hideUrlBar": true, //"toolbarTopFixedTitle": "Fixed title",
//"toolbarTop": false, //"hideUrlBar": true,
//"toolbarBottom": false //"toolbarTop": false,
}); //"toolbarBottom": false
});
}, },
child: Text("Open InAppBrowser") child: Text("Open InAppBrowser")
), ),
......
...@@ -79,6 +79,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio ...@@ -79,6 +79,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
var tmpWindow: UIWindow? var tmpWindow: UIWindow?
var browserOptions: InAppBrowserOptions? var browserOptions: InAppBrowserOptions?
var initHeaders: [String: String]? var initHeaders: [String: String]?
var isHidden = false
required init(coder aDecoder: NSCoder) { required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)! super.init(coder: aDecoder)!
......
...@@ -87,6 +87,9 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -87,6 +87,9 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
self.webViewController?.webView.stopLoading() self.webViewController?.webView.stopLoading()
result(true) result(true)
break break
case "isHidden":
result((self.webViewController?.isHidden ?? false) == true)
break
case "injectScriptCode": case "injectScriptCode":
self.injectScriptCode(arguments: arguments!, result: result) self.injectScriptCode(arguments: arguments!, result: result)
break break
...@@ -176,76 +179,97 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -176,76 +179,97 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let browserOptions = InAppBrowserOptions() let browserOptions = InAppBrowserOptions()
browserOptions.parse(options: options) 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
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
if !(self.tmpWindow != nil) { let tmpController = UIViewController()
let frame: CGRect = UIScreen.main.bounds let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel
self.tmpWindow = UIWindow(frame: frame) 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
let storyboard = UIStoryboard(name: WEBVIEW_STORYBOARD, bundle: nil) self.tmpWindow?.windowLevel = 0.0
let vc = storyboard.instantiateViewController(withIdentifier: WEBVIEW_STORYBOARD_CONTROLLER_ID) UIApplication.shared.delegate?.window??.makeKeyAndVisible()
webViewController = vc as? InAppBrowserWebViewController if self.previousStatusBarStyle != -1 {
webViewController?.browserOptions = browserOptions UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: self.previousStatusBarStyle)!
webViewController?.tmpWindow = tmpWindow }
webViewController?.currentURL = url })
webViewController?.initHeaders = headers
webViewController?.navigationDelegate = self
} }
else {
if !browserOptions.hidden { tmpController.present(webViewController!, animated: true, completion: nil)
show()
} }
} }
public func show() { public func show() {
if webViewController == nil { if webViewController == nil {
print("Tried to show IAB after it was closed.") print("Tried to hide IAB after it was closed.")
return
}
if previousStatusBarStyle != -1 {
print("Tried to show IAB while already shown")
return 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. // Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in DispatchQueue.main.async(execute: {() -> Void in
if weakSelf?.webViewController != nil { if self.webViewController != nil {
if !(self.tmpWindow != nil) {
let frame: CGRect = UIScreen.main.bounds
self.tmpWindow = UIWindow(frame: frame)
}
let tmpController = UIViewController()
let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel
self.tmpWindow?.rootViewController = tmpController
self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1) self.tmpWindow?.windowLevel = UIWindowLevel(baseWindowLevel! + 1)
self.tmpWindow?.makeKeyAndVisible() self.tmpWindow?.makeKeyAndVisible()
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
tmpController.present(self.webViewController!, animated: true, completion: nil) self.tmpWindow?.rootViewController?.present(self.webViewController!, animated: true, completion: nil)
} }
}) })
} }
public func hide() { public func hide() {
if webViewController == nil { if webViewController == nil {
print("Tried to hide IAB after it was closed.") print("Tried to hide IAB after it was closed.")
return return
} }
if previousStatusBarStyle == -1 {
print("Tried to hide IAB while already hidden") if self.webViewController != nil {
return self.webViewController?.isHidden = true
} }
previousStatusBarStyle = UIApplication.shared.statusBarStyle.rawValue
// Run later to avoid the "took a long time" log message. // Run later to avoid the "took a long time" log message.
DispatchQueue.main.async(execute: {() -> Void in DispatchQueue.main.async(execute: {() -> Void in
if self.webViewController != nil { if self.webViewController != nil {
self.previousStatusBarStyle = -1
self.webViewController?.presentingViewController?.dismiss(animated: true, completion: {() -> Void in self.webViewController?.presentingViewController?.dismiss(animated: true, completion: {() -> Void in
self.tmpWindow?.windowLevel = 0.0 self.tmpWindow?.windowLevel = 0.0
UIApplication.shared.delegate?.window??.makeKeyAndVisible() 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 { ...@@ -345,8 +369,6 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue: previousStatusBarStyle)! 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 { ...@@ -173,8 +173,13 @@ class InAppBrowser {
return await _channel.invokeMethod('stopLoading'); 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`) ///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>{}; Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('source', () => source); args.putIfAbsent('source', () => source);
return await _channel.invokeMethod('injectScriptCode', args); 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