From b6e7699ef8be56a5cecb4158b643fbb83da80a90 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Thu, 20 Oct 2022 18:55:30 +0200 Subject: [PATCH] Merge fixes of version 5.5.0+5 --- CHANGELOG.md | 10 ++++++++++ .../InAppWebViewStatic.java | 9 +++++++-- .../HeadlessInAppWebView.java | 19 ++++++++++++------- .../HeadlessInAppWebViewManager.java | 11 ++++++++--- .../in_app_webview/FlutterWebView.java | 7 ------- example/lib/in_app_webiew_example.screen.dart | 3 +-- example/lib/main.dart | 11 ----------- pubspec.yaml | 2 +- 8 files changed, 39 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 980f34f6..403f7b95 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.0-beta.5 + +- Merge fixes of version `5.5.0+5` + ## 6.0.0-beta.4 - Added `InAppWebView.headlessWebView` property to convert an `HeadlessWebView` to `InAppWebView` widget @@ -50,6 +54,12 @@ - Removed `URLProtectionSpace.iosIsProxy` property - `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null` +## 5.5.0+5 + +- Fixed `HeadlessInAppWebView` default size on Android +- Fixed "🐞[Android] execution of the workmanager destroys in_app_webview library's platform channel" [#1348](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1348) +- Fixed "HeadlessInAppWebView called from WorkManager background task triggers NullPointerException on missing context" [#912](https://github.com/pichillilorenzo/flutter_inappwebview/issues/912) + ## 5.5.0+4 - Fixed "Many crashes on iOS: Completion handler was not called" [#1221](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java index 8fdcc4e8..816adb88 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java @@ -1,5 +1,6 @@ package com.pichillilorenzo.flutter_inappwebview; +import android.content.Context; import android.content.pm.PackageInfo; import android.os.Build; import android.webkit.ValueCallback; @@ -81,8 +82,12 @@ public class InAppWebViewStatic extends ChannelDelegateImpl { result.success(false); break; case "getCurrentWebViewPackage": - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && plugin != null && plugin.activity != null) { - result.success(convertWebViewPackageToMap(WebViewCompat.getCurrentWebViewPackage(plugin.activity))); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && plugin != null && (plugin.activity != null || plugin.applicationContext != null)) { + Context context = plugin.activity; + if (context == null) { + context = plugin.applicationContext; + } + result.success(convertWebViewPackageToMap(WebViewCompat.getCurrentWebViewPackage(context))); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //with Android Lollipop (API 21) they started to update the WebView //as a separate APK with the PlayStore and they added the diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java index 768d07c8..6540a749 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebView.java @@ -45,6 +45,18 @@ public class HeadlessInAppWebView implements Disposable { } public void prepare(Map params) { + if (flutterWebView != null) { + View view = flutterWebView.getView(); + if (view != null) { + final Map initialSize = (Map) params.get("initialSize"); + Size2D size = Size2D.fromMap(initialSize); + if (size == null) { + size = new Size2D(-1, -1); + } + setSize(size); + view.setVisibility(View.INVISIBLE); + } + } if (plugin != null && plugin.activity != null) { // Add the headless WebView to the view hierarchy. // This way is also possible to take screenshots. @@ -54,14 +66,7 @@ public class HeadlessInAppWebView implements Disposable { if (mainView != null && flutterWebView != null) { View view = flutterWebView.getView(); if (view != null) { - final Map initialSize = (Map) params.get("initialSize"); - Size2D size = Size2D.fromMap(initialSize); - if (size == null) { - size = new Size2D(-1, -1); - } - setSize(size); mainView.addView(view, 0); - view.setVisibility(View.INVISIBLE); } } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebViewManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebViewManager.java index 62409008..1324c2ed 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebViewManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/headless_in_app_webview/HeadlessInAppWebViewManager.java @@ -21,6 +21,8 @@ package com.pichillilorenzo.flutter_inappwebview.headless_in_app_webview; +import android.content.Context; + import androidx.annotation.Nullable; import androidx.annotation.NonNull; @@ -67,9 +69,12 @@ public class HeadlessInAppWebViewManager extends ChannelDelegateImpl { } public void run(String id, HashMap params) { - if (plugin == null || plugin.activity == null) return; - - FlutterWebView flutterWebView = new FlutterWebView(plugin, plugin.activity, id, params); + if (plugin == null || (plugin.activity == null && plugin.applicationContext == null)) return; + Context context = plugin.activity; + if (context == null) { + context = plugin.applicationContext; + } + FlutterWebView flutterWebView = new FlutterWebView(plugin, context, id, params); HeadlessInAppWebView headlessInAppWebView = new HeadlessInAppWebView(plugin, id, flutterWebView); HeadlessInAppWebViewManager.webViews.put(id, headlessInAppWebView); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/FlutterWebView.java index 3ff6ddc9..faa4e750 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/FlutterWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/FlutterWebView.java @@ -57,13 +57,6 @@ public class FlutterWebView implements PlatformWebView { InAppWebViewSettings customSettings = new InAppWebViewSettings(); customSettings.parse(initialSettings); - if (plugin == null || plugin.activity == null) { - Log.e(LOG_TAG, "\n\n\nERROR: You need to upgrade your Flutter project to use the new Java Embedding API:\n\n" + - "- Take a look at the \"IMPORTANT Note for Android\" section here: https://github.com/pichillilorenzo/flutter_inappwebview#important-note-for-android\n" + - "- See the official wiki here: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects\n\n\n"); - return; - } - List userScripts = new ArrayList<>(); if (initialUserScripts != null) { for (Map initialUserScript : initialUserScripts) { diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index 39a33dff..30ab98c8 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -114,9 +114,8 @@ class _InAppWebViewExampleScreenState extends State { children: [ InAppWebView( key: webViewKey, - headlessWebView: headlessWebView, initialUrlRequest: - URLRequest(url: Uri.parse('https://google.com')), + URLRequest(url: Uri.parse('https://flutter.dev')), // initialUrlRequest: // URLRequest(url: Uri.parse(Uri.base.toString().replaceFirst("/#/", "/") + 'page.html')), // initialFile: "assets/index.html", diff --git a/example/lib/main.dart b/example/lib/main.dart index 63aa79bf..24450208 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -15,13 +15,6 @@ import 'package:pointer_interceptor/pointer_interceptor.dart'; InAppLocalhostServer localhostServer = new InAppLocalhostServer(documentRoot: 'assets'); -var headlessWebView = new HeadlessInAppWebView( - initialUrlRequest: URLRequest(url: Uri.parse('https://flutter.dev')), - shouldOverrideUrlLoading: (controller, navigationAction) async { - return NavigationActionPolicy.ALLOW; - }, -); - Future main() async { WidgetsFlutterBinding.ensureInitialized(); // await Permission.camera.request(); @@ -36,10 +29,6 @@ Future main() async { await localhostServer.start(); } - headlessWebView.run(); - - await Future.delayed(Duration(seconds: 1)); - runApp(MyApp()); } diff --git a/pubspec.yaml b/pubspec.yaml index 47f88698..f3f59d36 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 6.0.0-beta.4 +version: 6.0.0-beta.5 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues