diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d90d742..17600c944 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - Fixed "Unexpected behavior when using a null initialUrlRequest" [#1063](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1063) - Fixed "Local storage & cookie didn't persist when sharedCookie and cache both enabled" [#1092](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1092) - Fixed "ios zoomBy crash: Foundation/NSNumber.swift:467: Fatal error: Unable to bridge NSNumber to Float" [#873](https://github.com/pichillilorenzo/flutter_inappwebview/issues/873) +- Fixed "In App Browser Crashing in Android - Action Bar is null" [#1137](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1137) +- Fixed "Cannot load Javascript on some Android devices - Uncaught TypeError: Cannot read property 'appendChild' of null" [#888](https://github.com/pichillilorenzo/flutter_inappwebview/issues/888) - Merged "Update Options.swift" [#889](https://github.com/pichillilorenzo/flutter_inappwebview/pull/889) (thanks to [cloudygeek](https://github.com/cloudygeek)) - Merged "fix: Applicatio nNameForUserAgent is not working in iOS" [#1095](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1095) (thanks to [sunalwaysknows](https://github.com/sunalwaysknows)) - Merged "Make sure we open a new instance of a custom chrome chrome tab" [#812](https://github.com/pichillilorenzo/flutter_inappwebview/pull/812) (thanks to [savy-91](https://github.com/savy-91)) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserActivity.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserActivity.java index f63840cb8..dd35fb3a3 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserActivity.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_browser/InAppBrowserActivity.java @@ -20,6 +20,7 @@ import android.widget.ProgressBar; import android.widget.SearchView; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; @@ -50,6 +51,7 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow public String id; public InAppWebView webView; public PullToRefreshLayout pullToRefreshLayout; + @Nullable public ActionBar actionBar; public Menu menu; public SearchView searchView; @@ -179,17 +181,18 @@ private void prepareView() { else progressBar.setMax(100); - actionBar.setDisplayShowTitleEnabled(!options.hideTitleBar); + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(!options.hideTitleBar); - if (options.hideToolbarTop) - actionBar.hide(); - - if (options.toolbarTopBackgroundColor != null && !options.toolbarTopBackgroundColor.isEmpty()) - actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(options.toolbarTopBackgroundColor))); + if (options.hideToolbarTop) + actionBar.hide(); - if (options.toolbarTopFixedTitle != null && !options.toolbarTopFixedTitle.isEmpty()) - actionBar.setTitle(options.toolbarTopFixedTitle); + if (options.toolbarTopBackgroundColor != null && !options.toolbarTopBackgroundColor.isEmpty()) + actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(options.toolbarTopBackgroundColor))); + if (options.toolbarTopFixedTitle != null && !options.toolbarTopFixedTitle.isEmpty()) + actionBar.setTitle(options.toolbarTopFixedTitle); + } } @Override @@ -208,7 +211,7 @@ public boolean onCreateOptionsMenu(Menu m) { searchView.setQuery(webView.getUrl(), false); - if (options.toolbarTopFixedTitle == null || options.toolbarTopFixedTitle.isEmpty()) + if (actionBar != null && (options.toolbarTopFixedTitle == null || options.toolbarTopFixedTitle.isEmpty())) actionBar.setTitle(webView.getTitle()); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @@ -372,21 +375,24 @@ public void setOptions(InAppBrowserOptions newOptions, HashMap n progressBar.setMax(100); } - if (newOptionsMap.get("hideTitleBar") != null && options.hideTitleBar != newOptions.hideTitleBar) + if (actionBar != null && newOptionsMap.get("hideTitleBar") != null && options.hideTitleBar != newOptions.hideTitleBar) actionBar.setDisplayShowTitleEnabled(!newOptions.hideTitleBar); - if (newOptionsMap.get("hideToolbarTop") != null && options.hideToolbarTop != newOptions.hideToolbarTop) { + if (actionBar != null && newOptionsMap.get("hideToolbarTop") != null && options.hideToolbarTop != newOptions.hideToolbarTop) { if (newOptions.hideToolbarTop) actionBar.hide(); else actionBar.show(); } - if (newOptionsMap.get("toolbarTopBackgroundColor") != null && !Util.objEquals(options.toolbarTopBackgroundColor, newOptions.toolbarTopBackgroundColor) && + if (actionBar != null && newOptionsMap.get("toolbarTopBackgroundColor") != null && + !Util.objEquals(options.toolbarTopBackgroundColor, newOptions.toolbarTopBackgroundColor) && !newOptions.toolbarTopBackgroundColor.isEmpty()) actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(newOptions.toolbarTopBackgroundColor))); - if (newOptionsMap.get("toolbarTopFixedTitle") != null && !Util.objEquals(options.toolbarTopFixedTitle, newOptions.toolbarTopFixedTitle) && !newOptions.toolbarTopFixedTitle.isEmpty()) + if (actionBar != null && newOptionsMap.get("toolbarTopFixedTitle") != null && + !Util.objEquals(options.toolbarTopFixedTitle, newOptions.toolbarTopFixedTitle) && + !newOptions.toolbarTopFixedTitle.isEmpty()) actionBar.setTitle(newOptions.toolbarTopFixedTitle); if (newOptionsMap.get("hideUrlBar") != null && options.hideUrlBar != newOptions.hideUrlBar) { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java index e0de25173..c4afe58fe 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java @@ -1064,12 +1064,13 @@ public void injectJavascriptFileFromUrl(String urlFile, @Nullable Map c } } String jsWrapper = "(function(d) { var link = d.createElement('link'); link.rel='" + alternateStylesheet + "stylesheet'; link.type='text/css'; " + - cssLinkAttributes + " link.href = %s; d.head.appendChild(link); })(document);"; + cssLinkAttributes + " link.href = %s; if (d.head != null) { d.head.appendChild(link); } })(document);"; injectDeferredObject(urlFile, null, jsWrapper, null); } diff --git a/example/.gitignore b/example/.gitignore index 83ebb9e9b..c20d10dc1 100755 --- a/example/.gitignore +++ b/example/.gitignore @@ -70,3 +70,5 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +integration_test/.env.dart diff --git a/example/integration_test/.env.dart b/example/integration_test/.env.dart deleted file mode 100755 index 672d39f33..000000000 --- a/example/integration_test/.env.dart +++ /dev/null @@ -1 +0,0 @@ -final environment = {"NODE_SERVER_IP":"192.168.1.123"}; \ No newline at end of file diff --git a/example/integration_test/webview_flutter_test.dart b/example/integration_test/webview_flutter_test.dart index 15b574877..47e826fc3 100644 --- a/example/integration_test/webview_flutter_test.dart +++ b/example/integration_test/webview_flutter_test.dart @@ -5737,6 +5737,84 @@ setTimeout(function() { await chromeSafariBrowser.browserClosed.future; expect(chromeSafariBrowser.isOpened(), false); }); + + group('Android Custom Tabs', () { + test('Custom Tabs single instance', () async { + var chromeSafariBrowser = new MyChromeSafariBrowser(); + expect(chromeSafariBrowser.isOpened(), false); + + await chromeSafariBrowser.open( + url: Uri.parse("https://github.com/flutter"), + options: ChromeSafariBrowserClassOptions( + android: AndroidChromeCustomTabsOptions( + isSingleInstance: true + ) + ) + ); + await chromeSafariBrowser.browserCreated.future; + expect(chromeSafariBrowser.isOpened(), true); + expect(() async { + await chromeSafariBrowser.open( + url: Uri.parse("https://flutter.dev")); + }, throwsA(isInstanceOf())); + + await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes); + await chromeSafariBrowser.close(); + await chromeSafariBrowser.browserClosed.future; + expect(chromeSafariBrowser.isOpened(), false); + }); + + test('Trusted Web Activity', () async { + var chromeSafariBrowser = new MyChromeSafariBrowser(); + expect(chromeSafariBrowser.isOpened(), false); + + await chromeSafariBrowser.open( + url: Uri.parse("https://github.com/flutter"), + options: ChromeSafariBrowserClassOptions( + android: AndroidChromeCustomTabsOptions( + isTrustedWebActivity: true + ) + ) + ); + await chromeSafariBrowser.browserCreated.future; + expect(chromeSafariBrowser.isOpened(), true); + expect(() async { + await chromeSafariBrowser.open( + url: Uri.parse("https://flutter.dev")); + }, throwsA(isInstanceOf())); + + await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes); + await chromeSafariBrowser.close(); + await chromeSafariBrowser.browserClosed.future; + expect(chromeSafariBrowser.isOpened(), false); + }); + + test('Trusted Web Activity single instance', () async { + var chromeSafariBrowser = new MyChromeSafariBrowser(); + expect(chromeSafariBrowser.isOpened(), false); + + await chromeSafariBrowser.open( + url: Uri.parse("https://github.com/flutter"), + options: ChromeSafariBrowserClassOptions( + android: AndroidChromeCustomTabsOptions( + isTrustedWebActivity: true, + isSingleInstance: true + ) + ) + ); + await chromeSafariBrowser.browserCreated.future; + expect(chromeSafariBrowser.isOpened(), true); + expect(() async { + await chromeSafariBrowser.open( + url: Uri.parse("https://flutter.dev")); + }, throwsA(isInstanceOf())); + + await expectLater(chromeSafariBrowser.firstPageLoaded.future, completes); + await chromeSafariBrowser.close(); + await chromeSafariBrowser.browserClosed.future; + expect(chromeSafariBrowser.isOpened(), false); + }); + }, skip: !Platform.isAndroid); }); group('InAppLocalhostServer', () { diff --git a/pubspec.yaml b/pubspec.yaml index fdb7b0107..861af6fd1 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pedantic: ^1.10.0-nullsafety.1 + pedantic: ^1.11.1 # For information on the generic Dart part of this file, see the # following page: https://www.dartlang.org/tools/pub/pubspec