Commit 4d3a1789 authored by pichillilorenzo's avatar pichillilorenzo

fixed webview closing on android

parent aa583ad6
This diff is collapsed.
## 0.1.0
- updated/added new methods
- updated UI of android/iOS in-app browser
- code cleanup
- added new options when opening the in-app browser
## 0.0.1 ## 0.0.1
Initial release. Initial release.
This diff is collapsed.
...@@ -436,8 +436,8 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -436,8 +436,8 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
} }
public void close() { public static void close() {
this.activity.runOnUiThread(new Runnable() { registrar.activity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
......
...@@ -9,27 +9,28 @@ import java.util.HashMap; ...@@ -9,27 +9,28 @@ import java.util.HashMap;
public class InAppBrowserOptions { public class InAppBrowserOptions {
boolean useShouldOverrideUrlLoading = false;
boolean clearCache = false; boolean clearCache = false;
boolean clearSessionCache = false;
String userAgent = ""; String userAgent = "";
boolean progressBar = true; boolean javaScriptEnabled = true;
boolean javaScriptCanOpenWindowsAutomatically = false;
boolean hidden = false; boolean hidden = false;
boolean toolbarTop = true; boolean toolbarTop = true;
String toolbarTopBackgroundColor = ""; String toolbarTopBackgroundColor = "";
String toolbarTopFixedTitle = ""; String toolbarTopFixedTitle = "";
boolean hideUrlBar = false; boolean hideUrlBar = false;
boolean mediaPlaybackRequiresUserGesture = true;
boolean hideTitleBar = false; boolean hideTitleBar = false;
boolean closeOnCannotGoBack = true; boolean closeOnCannotGoBack = true;
boolean mediaPlaybackRequiresUserGesture = true; boolean clearSessionCache = false;
boolean javaScriptCanOpenWindowsAutomatically = false;
boolean javaScriptEnabled = true;
boolean builtInZoomControls = false; boolean builtInZoomControls = false;
boolean supportZoom = true; boolean supportZoom = true;
boolean databaseEnabled = true; boolean databaseEnabled = false;
boolean domStorageEnabled = true; boolean domStorageEnabled = false;
boolean useWideViewPort = true; boolean useWideViewPort = true;
boolean safeBrowsingEnabled = true; boolean safeBrowsingEnabled = true;
boolean useShouldOverrideUrlLoading = false; boolean progressBar = true;
public void parse(HashMap<String, Object> options) { public void parse(HashMap<String, Object> options) {
Iterator it = options.entrySet().iterator(); Iterator it = options.entrySet().iterator();
......
...@@ -143,10 +143,8 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -143,10 +143,8 @@ public class WebViewActivity extends AppCompatActivity {
else else
settings.setTextZoom(100); settings.setTextZoom(100);
if (options.progressBar) { if (options.progressBar)
progressBar = findViewById(R.id.progressBar); progressBar = findViewById(R.id.progressBar);
progressBar.setMax(100);
}
actionBar.setDisplayShowTitleEnabled(!options.hideTitleBar); actionBar.setDisplayShowTitleEnabled(!options.hideTitleBar);
...@@ -242,13 +240,14 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -242,13 +240,14 @@ public class WebViewActivity extends AppCompatActivity {
if (canGoBack()) if (canGoBack())
goBack(); goBack();
else if (options.closeOnCannotGoBack) else if (options.closeOnCannotGoBack)
close(); InAppBrowserFlutterPlugin.close();
return true; return true;
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void close() { public void close() {
hide();
finish(); finish();
} }
...@@ -277,15 +276,15 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -277,15 +276,15 @@ public class WebViewActivity extends AppCompatActivity {
public void hide() { public void hide() {
isHidden = true; isHidden = true;
Intent openMainActivity= new Intent(this, InAppBrowserFlutterPlugin.registrar.activity().getClass()); Intent openActivity = new Intent(this, InAppBrowserFlutterPlugin.registrar.activity().getClass());
openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openMainActivity, 0); startActivityIfNeeded(openActivity, 0);
} }
public void show() { public void show() {
isHidden = false; isHidden = false;
Intent openMainActivity= new Intent(InAppBrowserFlutterPlugin.registrar.activity(), WebViewActivity.class); Intent openActivity = new Intent(InAppBrowserFlutterPlugin.registrar.activity(), WebViewActivity.class);
openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openMainActivity, 0); startActivityIfNeeded(openActivity, 0);
} }
public void stopLoading(){ public void stopLoading(){
...@@ -338,7 +337,7 @@ public class WebViewActivity extends AppCompatActivity { ...@@ -338,7 +337,7 @@ public class WebViewActivity extends AppCompatActivity {
} }
public void closeButtonClicked(MenuItem item) { public void closeButtonClicked(MenuItem item) {
close(); InAppBrowserFlutterPlugin.close();
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:orientation="vertical" tools:context=".WebViewActivity"
tools:context=".WebViewActivity"> android:focusable="true">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"
style="@android:style/Widget.Holo.ProgressBar.Horizontal" style="@android:style/Widget.Holo.ProgressBar.Horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="3dp" android:layout_height="5dp"
android:layout_gravity="top" android:max="100"
android:progress="0" android:progress="0" />
android:visibility="gone" />
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout> </RelativeLayout>
...@@ -29,17 +29,19 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -29,17 +29,19 @@ class MyInAppBrowser extends InAppBrowser {
// x; // x;
// """)); // """));
//print("\n\n ${await this.isHidden()} \n\n"); //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..." )
""");
this.injectStyleCode(""" // await this.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js");
body { // this.injectScriptCode("""
background-color: #3c3c3c !important; // \$( "body" ).html( "Next Step..." )
} // """);
"""); //
this.injectStyleFile("https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css");*/ // // add custom css
// this.injectStyleCode("""
// body {
// background-color: #3c3c3c !important;
// }
// """);
// this.injectStyleFile("https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css");
} }
@override @override
......
...@@ -10,35 +10,35 @@ import Foundation ...@@ -10,35 +10,35 @@ import Foundation
@objcMembers @objcMembers
public class InAppBrowserOptions: NSObject { public class InAppBrowserOptions: NSObject {
var closeButtonCaption = "" var useShouldOverrideUrlLoading = false
var closeButtonColor = ""
var clearCache = false var clearCache = false
var userAgent = "" var userAgent = ""
var spinner = true var javaScriptEnabled = true
var javaScriptCanOpenWindowsAutomatically = false
var hidden = false var hidden = false
var disallowOverScroll = false
var toolbarTop = true var toolbarTop = true
var toolbarTopBackgroundColor = "" var toolbarTopBackgroundColor = ""
var toolbarTopTranslucent = true var hideUrlBar = false
var mediaPlaybackRequiresUserGesture = true
var disallowOverScroll = false
var toolbarBottom = true var toolbarBottom = true
var toolbarBottomBackgroundColor = "" var toolbarBottomBackgroundColor = ""
var toolbarBottomTranslucent = true var toolbarBottomTranslucent = true
var hideUrlBar = false var closeButtonCaption = ""
var closeButtonColor = ""
var presentationStyle = 0 //fullscreen var presentationStyle = 0 //fullscreen
var transitionStyle = 0 //crossDissolve var transitionStyle = 0 //crossDissolve
var enableViewportScale = false var enableViewportScale = false
var keyboardDisplayRequiresUserAction = true var keyboardDisplayRequiresUserAction = true
var suppressesIncrementalRendering = false var suppressesIncrementalRendering = false
var allowsAirPlayForMediaPlayback = true var allowsAirPlayForMediaPlayback = true
var mediaTypesRequiringUserActionForPlayback = "none"
var allowsBackForwardNavigationGestures = true var allowsBackForwardNavigationGestures = true
var allowsLinkPreview = true var allowsLinkPreview = true
var ignoresViewportScaleLimits = false var ignoresViewportScaleLimits = false
var allowsInlineMediaPlayback = false var allowsInlineMediaPlayback = false
var allowsPictureInPictureMediaPlayback = true var allowsPictureInPictureMediaPlayback = true
var javaScriptCanOpenWindowsAutomatically = false var spinner = true
var javaScriptEnabled = true
var useShouldOverrideUrlLoading = false
override init(){ override init(){
super.init() super.init()
......
...@@ -206,29 +206,20 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio ...@@ -206,29 +206,20 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
let jscriptWebkitTouchCallout = WKUserScript(source: "document.body.style.webkitTouchCallout='none';", injectionTime: .atDocumentEnd, forMainFrameOnly: true) let jscriptWebkitTouchCallout = WKUserScript(source: "document.body.style.webkitTouchCallout='none';", injectionTime: .atDocumentEnd, forMainFrameOnly: true)
self.webView.configuration.userContentController.addUserScript(jscriptWebkitTouchCallout) self.webView.configuration.userContentController.addUserScript(jscriptWebkitTouchCallout)
if (browserOptions?.mediaTypesRequiringUserActionForPlayback)! != "" {
if #available(iOS 10.0, *) { if #available(iOS 10.0, *) {
switch (browserOptions?.mediaTypesRequiringUserActionForPlayback)! { if (browserOptions?.mediaPlaybackRequiresUserGesture)! {
case "all": self.webView.configuration.mediaTypesRequiringUserActionForPlayback = .all
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = .all
break
case "audio":
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = .audio
break
case "video":
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = .video
break
default:
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = []
break
}
} else {
// Fallback on earlier versions
self.webView.configuration.mediaPlaybackRequiresUserAction = true
} }
else {
self.webView.configuration.mediaTypesRequiringUserActionForPlayback = []
}
} else {
// Fallback on earlier versions
self.webView.configuration.mediaPlaybackRequiresUserAction = (browserOptions?.mediaPlaybackRequiresUserGesture)!
} }
self.webView.configuration.allowsInlineMediaPlayback = (browserOptions?.allowsInlineMediaPlayback)! self.webView.configuration.allowsInlineMediaPlayback = (browserOptions?.allowsInlineMediaPlayback)!
self.webView.keyboardDisplayRequiresUserAction = browserOptions?.keyboardDisplayRequiresUserAction self.webView.keyboardDisplayRequiresUserAction = browserOptions?.keyboardDisplayRequiresUserAction
self.webView.configuration.suppressesIncrementalRendering = (browserOptions?.suppressesIncrementalRendering)! self.webView.configuration.suppressesIncrementalRendering = (browserOptions?.suppressesIncrementalRendering)!
......
This diff is collapsed.
name: flutter_inappbrowser name: flutter_inappbrowser
description: A Flutter plugin that allows you to open an in-app browser window. (porting of the popular cordova-plugin-inappbrowser). description: A Flutter plugin that allows you to open an in-app browser window. (inspired by the popular cordova-plugin-inappbrowser).
version: 0.0.1 version: 0.1.0
author: Lorenzo Pichilli <pichillilorenzo@gmail.com> author: Lorenzo Pichilli <pichillilorenzo@gmail.com>
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser homepage: https://github.com/pichillilorenzo/flutter_inappbrowser
......
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