Commit db65f7a0 authored by pichillilorenzo's avatar pichillilorenzo

updated README.md and documentation

parent b3cdd8bf
This diff is collapsed.
## 0.2.0 ## 0.2.0
- added support of Chrome CustomTabs for android - added support of Chrome CustomTabs for Android
- added support of SFSafariViewController for iOS - added support of SFSafariViewController for iOS
- added the ability to create multiple instances of browsers - added the ability to create multiple instances of browsers
......
This diff is collapsed.
...@@ -485,30 +485,32 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -485,30 +485,32 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
public static void close(final String uuid) { public static void close(final String uuid) {
final WebViewActivity webViewActivity = webViewActivities.get(uuid); final WebViewActivity webViewActivity = webViewActivities.get(uuid);
registrar.activity().runOnUiThread(new Runnable() { if (webViewActivity != null) {
@Override registrar.activity().runOnUiThread(new Runnable() {
public void run() { @Override
public void run() {
Map<String, Object> obj = new HashMap<>();
obj.put("uuid", uuid); Map<String, Object> obj = new HashMap<>();
channel.invokeMethod("onExit", obj); obj.put("uuid", uuid);
channel.invokeMethod("onExit", obj);
// The JS protects against multiple calls, so this should happen only when
// close() is called by other native code. // The JS protects against multiple calls, so this should happen only when
if (webViewActivity == null) // close() is called by other native code.
return; if (webViewActivity == null)
return;
webViewActivity.webView.setWebViewClient(new WebViewClient() {
// NB: wait for about:blank before dismissing webViewActivity.webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) { // NB: wait for about:blank before dismissing
webViewActivity.close(); public void onPageFinished(WebView view, String url) {
webViewActivity.close();
}
});
// NB: From SDK 19: "If you call methods on WebView from any thread
// other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads
webViewActivity.webView.loadUrl("about:blank");
} }
}); });
// NB: From SDK 19: "If you call methods on WebView from any thread }
// other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads
webViewActivity.webView.loadUrl("about:blank");
}
});
} }
} }
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart'; import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class MyInAppBrowser extends InAppBrowser { class MyInAppBrowser extends InAppBrowser {
@override @override
Future onLoadStart(String url) async { Future onLoadStart(String url) async {
print("\n\nStarted aaa $url\n\n"); print("\n\nStarted $url\n\n");
inAppBrowserFallback2.open("https://www.google.com", options: {
"hidden": true
});
//print("\n\n ${await this.isHidden()} \n\n"); //print("\n\n ${await this.isHidden()} \n\n");
} }
@override @override
Future onLoadStop(String url) async { Future onLoadStop(String url) async {
print("\n\nStopped aaa $url\n\n"); print("\n\nStopped $url\n\n");
inAppBrowserFallback2.show();
// 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("""
...@@ -65,40 +60,10 @@ class MyInAppBrowser extends InAppBrowser { ...@@ -65,40 +60,10 @@ class MyInAppBrowser extends InAppBrowser {
} }
} }
class MyInAppBrowser2 extends InAppBrowser {
@override
Future onLoadStart(String url) async {
print("\n\nStarted $url\n\n");
//print("\n\n ${await this.isHidden()} \n\n");
}
@override
Future onLoadStop(String url) async {
print("\n\nStopped $url\n\n");
}
@override
void onLoadError(String url, int code, String message) {
print("\n\nCan't load $url.. Error: $message\n\n");
}
@override
void onExit() {
print("\n\nBrowser closed!\n\n");
}
@override
void shouldOverrideUrlLoading(String url) {
print("\n\n override $url\n\n");
this.loadUrl(url);
}
}
MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser(); MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser();
MyInAppBrowser2 inAppBrowserFallback2 = new MyInAppBrowser2();
class MyChromeSafariBrowser extends ChromeSafariBrowser { class MyChromeSafariBrowser extends ChromeSafariBrowser {
MyChromeSafariBrowser(browserFallback) : super(browserFallback); MyChromeSafariBrowser(browserFallback) : super(browserFallback);
@override @override
...@@ -114,7 +79,6 @@ class MyChromeSafariBrowser extends ChromeSafariBrowser { ...@@ -114,7 +79,6 @@ class MyChromeSafariBrowser extends ChromeSafariBrowser {
@override @override
void onClosed() { void onClosed() {
print("ChromeSafari browser closed"); print("ChromeSafari browser closed");
inAppBrowserFallback.open("https://flutter.io/");
} }
} }
...@@ -143,20 +107,7 @@ class _MyAppState extends State<MyApp> { ...@@ -143,20 +107,7 @@ class _MyAppState extends State<MyApp> {
), ),
body: new Center( body: new Center(
child: new RaisedButton(onPressed: () { child: new RaisedButton(onPressed: () {
chromeSafariBrowser.open("https://flutter.io/", options: { chromeSafariBrowser.open("https://flutter.io/");
"addShareButton": false,
"toolbarBackgroundColor": "#000000",
"dismissButtonStyle": 1,
"preferredBarTintColor": "#000000",
},
optionsFallback: {
"hidden": true,
//"toolbarTopFixedTitle": "Fixed title",
//"useShouldOverrideUrlLoading": true
//"hideUrlBar": true,
//"toolbarTop": false,
//"toolbarBottom": false
});
// inAppBrowserFallback.open("https://flutter.io/", options: { // inAppBrowserFallback.open("https://flutter.io/", options: {
// //"hidden": true, // //"hidden": true,
// //"toolbarTopFixedTitle": "Fixed title", // //"toolbarTopFixedTitle": "Fixed title",
......
...@@ -15,6 +15,8 @@ public class SafariBrowserOptions: Options { ...@@ -15,6 +15,8 @@ public class SafariBrowserOptions: Options {
var dismissButtonStyle = 0 //done var dismissButtonStyle = 0 //done
var preferredBarTintColor = "" var preferredBarTintColor = ""
var preferredControlTintColor = "" var preferredControlTintColor = ""
var presentationStyle = 0 //fullscreen
var transitionStyle = 0 //crossDissolve
override init(){ override init(){
super.init() super.init()
......
...@@ -34,6 +34,9 @@ class SafariViewController: SFSafariViewController, SFSafariViewControllerDelega ...@@ -34,6 +34,9 @@ class SafariViewController: SFSafariViewController, SFSafariViewControllerDelega
self.preferredControlTintColor = color(fromHexString: (safariOptions?.preferredControlTintColor)!) self.preferredControlTintColor = color(fromHexString: (safariOptions?.preferredControlTintColor)!)
} }
} }
self.modalPresentationStyle = UIModalPresentationStyle(rawValue: (safariOptions?.presentationStyle)!)!
self.modalTransitionStyle = UIModalTransitionStyle(rawValue: (safariOptions?.transitionStyle)!)!
} }
func close() { func close() {
......
...@@ -303,7 +303,7 @@ class ChromeSafariBrowser { ...@@ -303,7 +303,7 @@ class ChromeSafariBrowser {
String uuid; String uuid;
InAppBrowser browserFallback; InAppBrowser browserFallback;
/// ///Initialize the [ChromeSafariBrowser] instance with a [InAppBrowser] fallback instance or `null`.
ChromeSafariBrowser (bf) { ChromeSafariBrowser (bf) {
uuid = uuidGenerator.v4(); uuid = uuidGenerator.v4();
browserFallback = bf; browserFallback = bf;
...@@ -325,7 +325,33 @@ class ChromeSafariBrowser { ...@@ -325,7 +325,33 @@ class ChromeSafariBrowser {
return new Future.value(""); return new Future.value("");
} }
///Opens an [url] in a new [ChromeSafariBrowser] instance or the system browser.
///
///- [url]: The [url] to load. Call [encodeUriComponent()] on this if the [url] contains Unicode characters.
///
///- [options]: Options for the [ChromeSafariBrowser].
///
///- [headersFallback]: The additional header of the [InAppBrowser] instance fallback to be used in the HTTP request for this URL, specified as a map from name to value.
///
///- [optionsFallback]: Options used by the [InAppBrowser] instance fallback.
///
///**Android** supports these options:
///
///- __addShareButton__: Set to `false` if you don't want the default share button. The default value is `true`.
///- __showTitle__: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
///- __toolbarBackgroundColor__: Set the custom background color of the toolbar.
///- __enableUrlBarHiding__: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
///- __instantAppsEnabled__: Set to `true` to enable Instant Apps. The default value is `false`.
///
///**iOS** supports these options:
/// ///
///- __entersReaderIfAvailable__: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
///- __barCollapsingEnabled__: Set to `true` to enable bar collapsing. The default value is `false`.
///- __dismissButtonStyle__: Set the custom style for the dismiss button. The default value is `0 //done`. See [SFSafariViewController.DismissButtonStyle](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle) for all the available styles.
///- __preferredBarTintColor__: Set the custom background color of the navigation bar and the toolbar.
///- __preferredControlTintColor__: Set the custom color of the control buttons on the navigation bar and the toolbar.
///- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
///- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
Future<void> open(String url, {Map<String, dynamic> options = const {}, Map<String, String> headersFallback = const {}, Map<String, dynamic> optionsFallback = const {}}) async { Future<void> open(String url, {Map<String, dynamic> options = const {}, Map<String, String> headersFallback = const {}, Map<String, dynamic> optionsFallback = const {}}) async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('uuid', () => uuid); args.putIfAbsent('uuid', () => uuid);
......
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