-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android emulator using API 34 fails to draw on resume sometimes. #1981
Comments
👋 @dnfield NOTE: This comment is auto-generated. Are you sure you have already searched for the same problem? Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem! If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue. In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding Following these steps can save you, me, and other people a lot of time, thanks! |
See some additional context in comments starting from flutter/flutter#139630 (comment). I've hidden them in that issue because they're not relly relevant to it. /cc @xOldeVx fyi |
Could this be caused by not using Hybrid Composition on Android? |
@pichillilorenzo When not using hybrid composition, this does not reproduce with other platforms views. |
|
Here is the usage of that setting: flutter_inappwebview/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview.dart Lines 374 to 389 in 751a104
|
We do not recommend using hybrid composition on Android. |
@johnmccutchan as stated here https://github.com/flutter/flutter/wiki/Hybrid-Composition#android:
I think that, for WebViews, having "accessibility and keyboard related issues" fixed is kind of a MUST to have it working properly for end-users. Have you any advice? Something better? Thanks. |
Flutter has changed a lot since Flutter 1.2 (we are now on 3.16). Today, we recommend that you use Texture Layer Hybrid Composition (TLHC) mode and not Hybrid Composition or Virtual Display modes.
If you encounter issues with TLHC mode please file specific bugs with reproduction steps. |
Ok, I should play a little bit using Also, one important thing I remember was related to the native view performances. By the way, the official Here is also some useful links about HC in that file: |
I had done some debugging on this yesterday and the issue seems to be that when the Flutter engine asks the subview to draw itself, it's just not drawing anything. But I've only reproduced this issue on an API 34 emulator, and only with this particular webview plugin. I started trying to understand the way the Android views are setup in this plugin, but I think one of the authors here more familiar with the Android code would be better suited. My suspicion is that something in this plugin is getting the view hierarchy confused in this resume case. If you can boil things down to a smaller reproduction that points to a bug in the engine, I'm happy to take another look at it. |
@dnfield I haven't taken a look at the issue itself yet, unfortunately. By the way: This is the Android The Android
"Resume" is something related to the Android Activity, am I right? A developer can handle that on the Flutter side by calling InAppWebViewController.resume and InAppWebViewController.pause respectively. |
What we are saying:
We don't know why (3) is happening but it is unlikely to be an issue in Flutter itself given all the other platform view plugins work fine. So it is very likely an issue in flutter_inappwebview that you will need to debug and fix. We can't provide guidance on where your bug is or how you should fix it as we don't know your code. |
Indeed, I'm not asking that! As I said, I will take a look at the issue as soon as possible by myself (any help would be appreciated anyway). Anyway, I will let you know when I have news, thanks for the moment. |
I am not aware of any major bugs or gotchas in TLHC mode. If you encounter specific issues, please file bugs. |
@dnfield The option is Currently, setting that option to This is the current implementation: Lines 392 to 395 in 751a104
@johnmccutchan So, could it be an issue with the current Flutter Platform View Android implementation? A workaround that I can implement would be to use it only when Hybrid Composition is enabled.
Indeed, I tested again now just to check if something changed about rendering performance, but using HC for rendering Android native views still guarantees better rendering performance. I tried with the official Flutter version used for the test:
Plugins version:
Screen record: test.mp4This is the code that you can use to test it by yourself: import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late WebViewController? controller;
late InAppWebViewController? webViewController;
bool displayWithHybridComposition = false;
bool useOfficialWebViewFlutter = true;
@override
void initState() {
super.initState();
if (useOfficialWebViewFlutter) {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse('https://pub.dev'));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Using: ' + (useOfficialWebViewFlutter
? 'webview_flutter'
: 'flutter_inappwebview')),
actions: [
PopupMenuButton(itemBuilder: (context) {
return [
PopupMenuItem<int>(
value: 0,
child: Text("webview_flutter"),
),
PopupMenuItem<int>(
value: 1,
child: Text("flutter_inappwebview"),
),
];
}, onSelected: (value) {
setState(() {
useOfficialWebViewFlutter = value == 0;
});
}),
],
),
floatingActionButton: ElevatedButton(
child: Text('HC enabled: $displayWithHybridComposition'),
onPressed: () {
setState(() {
displayWithHybridComposition = !displayWithHybridComposition;
});
},
),
body: Container(
color: Colors.black,
child: useOfficialWebViewFlutter
? WebViewWidget.fromPlatformCreationParams(
params: AndroidWebViewWidgetCreationParams(
key: GlobalKey(),
controller: controller!.platform,
displayWithHybridComposition: displayWithHybridComposition))
: InAppWebView(
key: GlobalKey(),
initialSettings: InAppWebViewSettings(
useHybridComposition: displayWithHybridComposition,
),
onWebViewCreated: (controller) =>
webViewController = controller,
initialUrlRequest:
URLRequest(url: WebUri.uri(Uri.parse('https://pub.dev'))),
),
),
);
}
} Both plugins call Furthermore, for my plugin, I tried to use explicitly Without HC enabled, the scroll is more sluggish and there are more frame drops. So, I'm not saying that HC should be used or not, at least for WebViews. The APIs are there, the choice ultimately falls to the developer who will use them. Am I missing something? Is there something else that could boost rendering performance without using HC? Any advice or it is just as it is for now? In the meantime, thanks for the support to all of you! |
Here is more info about the issue with the native view Hardware acceleration enabled: if you rotate the device or open the keyboard or somehow you manage to get the Flutter widget that contains the native view to be resized, it draws it back correctly. By the way, the native view itself stills there and gestures still work correctly as the view was visible, it just doesn’t draw the “texture” or whatever it is for Android Flutter Platform View. |
My s22 Ultra got new firmware update and I can't reproduce this bug anymore, by the way if setting How can I select mode? I mean |
@xOldeVx you can’t now. That logic is not implemented, it was just a test of mine locally. |
I'm updating again again, the problem is still here, for some reason it's worked without any problem for few days, and now it's occurs almost every time. |
@xOldeVx as I said, this is not fixed yet! It requires a new version to be published when it is fixed. Unfortunately, Hybrid Composition comes with trade-offs on Flutter side animations, check: https://github.com/flutter/flutter/wiki/Hybrid-Composition#performance You should enable HC or not based on your App use cases. But, currently, as I said, the "resume" issue is not fixed yet. |
@pichillilorenzo Does it have an estimated date or a temporary solution, even not hermetic but only for Samsung Android 14 owners, because this problem is gaining momentum (more and more users update to Android 14) and I will probably have to move to another library in the meantime |
@xOldeVx sorry but I was focused on other things. |
@xOldeVx I have released the new |
You mean |
I’m not able to reproduce it anymore using the emulator. Also, it could be useful a screen record of what is happening. |
I checked it in the emulator (Pixel) and it's not reproduce anymore, right, but in real device Ultra S22 it's reproduce easy. Code:
A screenshot exactly like here: You need to switch to another app like in the video, and then back to your app by clicking on the icon (I recheck it, not only by clicking on the icon, also if you switch again to your app you see a black screen) |
The reproduction on the Samsung phone is probably a different bug. We're trying to work with Samsung to get it fixed. |
@dnfield do you mean that it's a bug of Flutter PlatformView? |
@xOldeVx When the black screen appears, if you change the phone orientation, does the WewbView become visible again? |
@pichillilorenzo Samsung broke something in their Android 14 release. They've told us it's fixed in their upcoming update 🤞 |
Is there a way to set |
* pichillilorenzo-master: (162 commits) added APPLINK_BLOCK to NavigationActionPolicy windows: removed not wanted debug log in in_app_webview.cpp initial windows implementation pichillilorenzo#460 added InAppWebViewControllerKeepAliveProps constructor parameters default value fix pichillilorenzo#1981 windows: added openDevTools, callDevToolsProtocolMethod, addDevToolsProtocolEventListener and removeDevToolsProtocolEventListener methods, added some more inappwebview and inappbrowser basic settings windows: completed CookieManager implementation, added WebViewEnvironment getAvailableVersion and compareBrowserVersions methods windows: updated webview environment docs, updated cookie manager to support webview environment windows: added WebViewEnvironment support for headlessinappwebview and inappbrowser windows: fixed some c++ include windows: fixed dealloc webviews logic, implemented takeScreenshot, added WebViewEnvironment and WebViewEnvironmentSettings classes windows: added headless inappwebview initial implementation windows: fixed javascript evaluation, added callAsyncJavaScript implementation, call DestroyWindow(parentWindow) on InAppWebView dealloc windows: fixed custom platform view context menu and window position windows: added content world support for user scripts and javascript evaluation windows: updated webview and browser creation params, added support for openWithSystemBrowser windows: completed initial javascript handler communication and user scripts support, added support for loadFile and loadData windows: implemented some other methods and events, initial implementation work for UserScripts and JavaScript handlers windows: added c++ nlohmann.json dependency, added getCopyBackForwardList implementation windows: added inappwebview widget support, added some other methods ...
Description
Launch this simple in app webview app on an Android emulator using API 34. It will fail to render once resumed from the background if you run some other "heavy" app between.
Expected behavior:
Run the app, place it in the background, run youtube, re-launch the app from its icon. It should render as normal.
Current behavior:
The app renders a black screen. This does not appear to be due to a bug in the Flutter engine, and does not reproduce with e.g.
webview_flutter
.The text was updated successfully, but these errors were encountered: