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