updated web support

This commit is contained in:
Lorenzo Pichilli 2022-04-27 17:50:30 +02:00
parent 68f25d0d4d
commit 2dd1999a63
5 changed files with 92 additions and 1 deletions

View File

@ -169,6 +169,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
this.url = url.toString(); this.url = url.toString();
urlController.text = this.url; urlController.text = this.url;
}); });
}, },
onLoadError: (controller, url, code, message) { onLoadError: (controller, url, code, message) {
pullToRefreshController?.endRefreshing(); pullToRefreshController?.endRefreshing();

View File

@ -497,6 +497,51 @@ window.flutter_inappwebview = {
} }
return null; return null;
}, },
getScrollX: function() {
var iframe = webView.iframe;
try {
return Math.round(iframe.contentWindow.scrollX);
} catch (e) {
console.log(e);
}
return null;
},
getScrollY: function() {
var iframe = webView.iframe;
try {
return Math.round(iframe.contentWindow.scrollY);
} catch (e) {
console.log(e);
}
return null;
},
isSecureContext: function() {
var iframe = webView.iframe;
try {
return iframe.contentWindow.isSecureContext;
} catch (e) {
console.log(e);
}
return false;
},
canScrollVertically: function() {
var iframe = webView.iframe;
try {
return iframe.contentDocument.body.scrollHeight > iframe.contentWindow.innerHeight;
} catch (e) {
console.log(e);
}
return false;
},
canScrollHorizontally: function() {
var iframe = webView.iframe;
try {
return iframe.contentDocument.body.scrollWidth > iframe.contentWindow.innerWidth;
} catch (e) {
console.log(e);
}
return false;
},
}; };
return webView; return webView;

View File

@ -2488,9 +2488,12 @@ class InAppWebViewController
///Returns the scrolled left position of the current WebView. ///Returns the scrolled left position of the current WebView.
/// ///
///**NOTE for Web**: this method will have effect only if the iframe has the same origin.
///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - View.getScrollX](https://developer.android.com/reference/android/view/View#getScrollX())) ///- Android native WebView ([Official API - View.getScrollX](https://developer.android.com/reference/android/view/View#getScrollX()))
///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset)) ///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset))
///- Web ([Official API - Window.scrollX](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX))
Future<int?> getScrollX() async { Future<int?> getScrollX() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('getScrollX', args); return await _channel.invokeMethod('getScrollX', args);
@ -2498,9 +2501,12 @@ class InAppWebViewController
///Returns the scrolled top position of the current WebView. ///Returns the scrolled top position of the current WebView.
/// ///
///**NOTE for Web**: this method will have effect only if the iframe has the same origin.
///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - View.getScrollY](https://developer.android.com/reference/android/view/View#getScrollY())) ///- Android native WebView ([Official API - View.getScrollY](https://developer.android.com/reference/android/view/View#getScrollY()))
///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset)) ///- iOS ([Official API - UIScrollView.contentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset))
///- Web ([Official API - Window.scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY))
Future<int?> getScrollY() async { Future<int?> getScrollY() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('getScrollY', args); return await _channel.invokeMethod('getScrollY', args);
@ -2731,9 +2737,12 @@ class InAppWebViewController
/// ///
///**NOTE for Android**: available Android 21.0+. ///**NOTE for Android**: available Android 21.0+.
/// ///
///**NOTE for Web**: this method will have effect only if the iframe has the same origin. Returns `false` otherwise.
///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
///- Android native WebView ///- Android native WebView
///- iOS ///- iOS
///- Web ([Official API - Window.isSecureContext](https://developer.mozilla.org/en-US/docs/Web/API/Window/isSecureContext))
Future<bool> isSecureContext() async { Future<bool> isSecureContext() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('isSecureContext', args); return await _channel.invokeMethod('isSecureContext', args);
@ -2959,9 +2968,12 @@ class InAppWebViewController
///Returns `true` if the webpage can scroll vertically, otherwise `false`. ///Returns `true` if the webpage can scroll vertically, otherwise `false`.
/// ///
///**NOTE for Web**: this method will have effect only if the iframe has the same origin.
///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
///- Android native WebView ///- Android native WebView
///- iOS ///- iOS
///- Web
Future<bool> canScrollVertically() async { Future<bool> canScrollVertically() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('canScrollVertically', args); return await _channel.invokeMethod('canScrollVertically', args);
@ -2969,9 +2981,12 @@ class InAppWebViewController
///Returns `true` if the webpage can scroll horizontally, otherwise `false`. ///Returns `true` if the webpage can scroll horizontally, otherwise `false`.
/// ///
///**NOTE for Web**: this method will have effect only if the iframe has the same origin.
///
///**Supported Platforms/Implementations**: ///**Supported Platforms/Implementations**:
///- Android native WebView ///- Android native WebView
///- iOS ///- iOS
///- Web
Future<bool> canScrollHorizontally() async { Future<bool> canScrollHorizontally() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('canScrollHorizontally', args); return await _channel.invokeMethod('canScrollHorizontally', args);

View File

@ -136,6 +136,16 @@ class InAppWebViewWebElement {
return await getOriginalUrl(); return await getOriginalUrl();
case "getSelectedText": case "getSelectedText":
return await getSelectedText(); return await getSelectedText();
case "getScrollX":
return await getScrollX();
case "getScrollY":
return await getScrollY();
case "isSecureContext":
return await isSecureContext();
case "canScrollVertically":
return await canScrollVertically();
case "canScrollHorizontally":
return await canScrollHorizontally();
case "dispose": case "dispose":
dispose(); dispose();
break; break;
@ -323,6 +333,26 @@ class InAppWebViewWebElement {
return _callMethod('getSelectedText'); return _callMethod('getSelectedText');
} }
Future<int?> getScrollX() async {
return _callMethod('getScrollX');
}
Future<int?> getScrollY() async {
return _callMethod('getScrollY');
}
Future<bool> isSecureContext() async {
return _callMethod('isSecureContext');
}
Future<bool> canScrollVertically() async {
return _callMethod('canScrollVertically');
}
Future<bool> canScrollHorizontally() async {
return _callMethod('canScrollHorizontally');
}
Set<Sandbox> getSandbox() { Set<Sandbox> getSandbox() {
var sandbox = iframe.sandbox; var sandbox = iframe.sandbox;
Set<Sandbox> values = Set(); Set<Sandbox> values = Set();

View File

@ -39,6 +39,6 @@ else
FAILED=1 FAILED=1
fi fi
kill $(jobs -p) jobs -p | xargs kill
exit $FAILED exit $FAILED