Skip to content

Commit

Permalink
Added onOverScrolled WebView event, updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Mar 22, 2021
1 parent 97edbe1 commit c22707d
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 47 deletions.
420 changes: 420 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added `WebMessageChannel` and `WebMessageListener` features
- Added `canScrollVertically` and `canScrollHorizontally` webview methods
- Added Android pull-to-refresh `setSize` method and `size` option
- Added `onOverScrolled` WebView event
- `AndroidInAppWebViewController.getCurrentWebViewPackage` is available now starting from Android API 21+
- Updated Android Gradle distributionUrl version to `5.6.4`
- Updated Android `androidx.webkit:webkit` to `1.4.0`, `androidx.browser:browser` to `1.3.0`, `androidx.appcompat:appcompat` to `1.2.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,21 @@ public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(ev);
}

// @Override
// protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
// super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
// }
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);

boolean overScrolledHorizontally = canScrollHorizontally() && clampedX;
boolean overScrolledVertically = canScrollVertically() && clampedY;
if (overScrolledHorizontally || overScrolledVertically) {
Map<String, Object> obj = new HashMap<>();
obj.put("x", scrollX);
obj.put("y", scrollY);
obj.put("clampedX", overScrolledHorizontally);
obj.put("clampedY", overScrolledVertically);
channel.invokeMethod("onOverScrolled", obj);
}
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/flutter/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-03-19 15:15:51.579916","version":"2.1.0-10.0.pre"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-03-22 15:18:36.048089","version":"2.1.0-10.0.pre"}
58 changes: 24 additions & 34 deletions example/integration_test/webview_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

if (Platform.isAndroid) {
AndroidInAppWebViewController.setWebContentsDebuggingEnabled(false);
AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
}

group('InAppWebView', () {
Expand Down Expand Up @@ -383,9 +383,9 @@ void main() {
await pageStarts.stream.firstWhere((String url) => url == currentUrl);
await pageLoads.stream.firstWhere((String url) => url == currentUrl);

final String content = await controller.evaluateJavascript(
final String? content = await controller.evaluateJavascript(
source: 'document.documentElement.innerText');
expect(content.contains('flutter_test_header'), isTrue);
expect(content!.contains('flutter_test_header'), isTrue);

pageStarts.close();
pageLoads.close();
Expand Down Expand Up @@ -1627,7 +1627,7 @@ void main() {

pageLoads.close();
},
skip: !Platform.isAndroid,
skip: true /* !Platform.isAndroid */,
);

testWidgets(
Expand Down Expand Up @@ -1751,7 +1751,7 @@ void main() {
controllerCompleter.complete(controller);
},
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
expect(ajaxRequest.data, "firstname=Foo&lastname=Bar");
assert(ajaxRequest.data == "firstname=Foo&lastname=Bar");

ajaxRequest.responseType = 'json';
ajaxRequest.data = "firstname=Foo2&lastname=Bar2";
Expand Down Expand Up @@ -1841,10 +1841,11 @@ void main() {
controllerCompleter.complete(controller);
},
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
expect(ajaxRequest.data, '{"firstname":"Foo","lastname":"Bar"}');
String data = ajaxRequest.data;
assert(data.contains('"firstname":"Foo"') && data.contains('"lastname":"Bar"'));

ajaxRequest.responseType = 'json';
ajaxRequest.data = "{'firstname': 'Foo2', 'lastname': 'Bar2'}";
ajaxRequest.data = '{"firstname": "Foo2", "lastname": "Bar2"}';
shouldInterceptAjaxPostRequestCompleter.complete(controller);
return ajaxRequest;
},
Expand Down Expand Up @@ -1929,7 +1930,7 @@ void main() {
controllerCompleter.complete(controller);
},
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
expect(ajaxRequest.data, "firstname=Foo&lastname=Bar");
assert(ajaxRequest.data == "firstname=Foo&lastname=Bar");

ajaxRequest.responseType = 'json';
ajaxRequest.data = "firstname=Foo2&lastname=Bar2";
Expand Down Expand Up @@ -2017,11 +2018,11 @@ void main() {
controllerCompleter.complete(controller);
},
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
expect(ajaxRequest.data, isNotNull);
assert(ajaxRequest.data != null);

var body = ajaxRequest.data.cast<int>();
var bodyString = String.fromCharCodes(body);
expect(bodyString.indexOf("WebKitFormBoundary") >= 0, true);
assert(bodyString.indexOf("WebKitFormBoundary") >= 0);

ajaxRequest.data = utf8.encode(bodyString.replaceFirst("Foo", "Foo2").replaceFirst("Bar", "Bar2"));
ajaxRequest.responseType = 'json';
Expand Down Expand Up @@ -2100,10 +2101,10 @@ void main() {
response.json().then(function(value) {
window.flutter_inappwebview.callHandler('fetchPost', value);
}).catch(function(error) {
window.flutter_inappwebview.callHandler('fetchPost', "ERROR: " + error);
window.flutter_inappwebview.callHandler('fetchPost', "ERROR: " + error);
});
}).catch(function(error) {
window.flutter_inappwebview.callHandler('fetchPost', "ERROR: " + error);
window.flutter_inappwebview.callHandler('fetchPost', "ERROR: " + error);
});
});
</script>
Expand All @@ -2126,7 +2127,7 @@ void main() {
});
},
shouldInterceptFetchRequest: (controller, fetchRequest) async {
expect(fetchRequest.body, "firstname=Foo&lastname=Bar");
assert(fetchRequest.body == "firstname=Foo&lastname=Bar");

fetchRequest.body = "firstname=Foo2&lastname=Bar2";
shouldInterceptFetchPostRequestCompleter.complete();
Expand All @@ -2136,9 +2137,6 @@ void main() {
),
);

var fetchGetCompleterValue = await fetchGetCompleter.future;
expect(fetchGetCompleterValue, '200');

await shouldInterceptFetchPostRequestCompleter.future;
var fetchPostCompleterValue = await fetchPostCompleter.future;

Expand Down Expand Up @@ -2213,19 +2211,17 @@ void main() {
});
},
shouldInterceptFetchRequest: (controller, fetchRequest) async {
expect(fetchRequest.body, '{"firstname":"Foo","lastname":"Bar"}');
String body = fetchRequest.body;
assert(body.contains('"firstname":"Foo"') && body.contains('"lastname":"Bar"'));

fetchRequest.body = "{'firstname': 'Foo2', 'lastname': 'Bar2'}";
fetchRequest.body = '{"firstname": "Foo2", "lastname": "Bar2"}';
shouldInterceptFetchPostRequestCompleter.complete();
return fetchRequest;
},
),
),
);

var fetchGetCompleterValue = await fetchGetCompleter.future;
expect(fetchGetCompleterValue, '200');

await shouldInterceptFetchPostRequestCompleter.future;
var fetchPostCompleterValue = await fetchPostCompleter.future;

Expand Down Expand Up @@ -2298,7 +2294,7 @@ void main() {
});
},
shouldInterceptFetchRequest: (controller, fetchRequest) async {
expect(fetchRequest.body, "firstname=Foo&lastname=Bar");
assert(fetchRequest.body == "firstname=Foo&lastname=Bar");

fetchRequest.body = "firstname=Foo2&lastname=Bar2";
shouldInterceptFetchPostRequestCompleter.complete();
Expand All @@ -2308,9 +2304,6 @@ void main() {
),
);

var fetchGetCompleterValue = await fetchGetCompleter.future;
expect(fetchGetCompleterValue, '200');

await shouldInterceptFetchPostRequestCompleter.future;
var fetchPostCompleterValue = await fetchPostCompleter.future;

Expand Down Expand Up @@ -2381,11 +2374,11 @@ void main() {
});
},
shouldInterceptFetchRequest: (controller, fetchRequest) async {
expect(fetchRequest.body, isNotNull);
assert(fetchRequest.body != null);

var body = fetchRequest.body.cast<int>();
var bodyString = String.fromCharCodes(body);
expect(bodyString.indexOf("WebKitFormBoundary") >= 0, true);
assert(bodyString.indexOf("WebKitFormBoundary") >= 0);

fetchRequest.body = utf8.encode(bodyString.replaceFirst("Foo", "Foo2").replaceFirst("Bar", "Bar2"));
shouldInterceptFetchPostRequestCompleter.complete();
Expand All @@ -2395,9 +2388,6 @@ void main() {
),
);

var fetchGetCompleterValue = await fetchGetCompleter.future;
expect(fetchGetCompleterValue, '200');

await shouldInterceptFetchPostRequestCompleter.future;
var fetchPostCompleterValue = await fetchPostCompleter.future;

Expand Down Expand Up @@ -2666,7 +2656,7 @@ void main() {
windowControllerCompleter.complete(controller);
},
onLoadStop: (controller, url) async {
if (url!.scheme != "about") {
if (url!.scheme != "about" && !windowPageLoaded.isCompleted) {
windowPageLoaded.complete(url.toString());
await controller.evaluateJavascript(
source: "window.close();");
Expand Down Expand Up @@ -4185,7 +4175,7 @@ setTimeout(function() {
await controller.injectJavascriptFileFromUrl(
urlFile: Uri.parse('https://code.jquery.com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(id: 'jquery'));
await Future.delayed(Duration(seconds: 2));
await Future.delayed(Duration(seconds: 4));
expect(
await controller.evaluateJavascript(
source: "document.body.querySelector('#jquery') == null;"),
Expand Down Expand Up @@ -5022,8 +5012,8 @@ setTimeout(function() {
jsObjectName: "myTestObj",
allowedOriginRules: Set.from(["https://*.example.com"]),
onPostMessage: (message, sourceOrigin, isMainFrame, replyProxy) {
expect(sourceOrigin.toString(), "https://www.example.com");
expect(isMainFrame, true);
assert(sourceOrigin.toString() == "https://www.example.com");
assert(isMainFrame);

replyProxy.postMessage(message! + " and back");
},
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/lorenzopichilli/flutter"
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart"
export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
Expand Down
1 change: 1 addition & 0 deletions flutter_inappwebview.iml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
Loading

0 comments on commit c22707d

Please sign in to comment.