-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter] Add new entrypoint that uses hybrid composition on Android #2883
[webview_flutter] Add new entrypoint that uses hybrid composition on Android #2883
Conversation
/// This flag is temporary and is highly subject to removal. One should only | ||
/// use this if they are willing to test [WebView] features that aren't | ||
/// available in the standard version and acknowledges that it is possible | ||
/// this can have slower performance and/or unpredictable bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it has slower performance necessarily. It depends on what is being measured and how relevant that is.
For example, this mode makes the webview itself much faster. The Flutter UI might be slower, but only on devices below Android 10. Only while the webview is rendered, and Flutter is producing a ton of frames. e.g. animations. That's really it. For the most part, these are pretty good trade-off for webview.
I'd change this description to point out that it's an experimental feature that appends the webview to the Android view hierarchy for better performance and compatibility.
That's it for now. Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, re: unpredictable bug. This is true for any new features, and it's definitely true for the current webview, which is the motivation behind this feature anyways. I think I will rephrase it as "this mode fixes many issues while interacting with the Android webview. For more, see flutter/flutter#61133"
/// this can have slower performance and/or unpredictable bugs. | ||
/// | ||
/// Defaults to false. | ||
final bool useExperimentalAndroidSurfaceView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about a separate .dart
file that has this feature on by default? This way, we have a BUILD
target that automatically adds the metadata to the Android Manifest.
@mehmetf do you have any preference about how to add this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this out, but this file has a lot of private methods/constructors that needed to be copy pasted to the new file. I went with a different approach and decided just create to a new WebViewPlatform
implementation that extends AndroidWebView
. So, now all a user needs to do is: WebView.platform = SurfaceAndroidWebView()
. What are your thoughts on that approach?
When hybrid views support will move to stable? Thanks! |
@pichillilorenzo It's on stable now |
FYI, the documentation is available on https://github.com/flutter/flutter/wiki/Hybrid-Composition |
This PR is waiting for dynamic thread merging. FYI @cyanglaz |
So this PR has been released in 1.20.0? |
`android/app/src/main/AndroidManifest.xml`: | ||
```xml | ||
<application> | ||
. | ||
. | ||
<meta-data | ||
android:name="io.flutter.embedded_views_preview" | ||
android:value="true" /> | ||
. | ||
. | ||
</application> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be needed in 1.22.
@amirh would you mind reviewing this PR as well? Here's what I had in mind so far:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code overall looks good, left a few nits mostly about documentation
@@ -64,6 +67,60 @@ enum NavigationDecision { | |||
navigate, | |||
} | |||
|
|||
/// Android [WebViewPlatform] that uses [AndroidViewSurface] to build the [WebView] widget. | |||
/// | |||
/// To use this, set [WebView.platform] to an instance of this class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add some guidance on when should one use it and what are the costs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. I added it below. @blasten What are your thoughts on the explanation below?
/// Android [WebViewPlatform] that uses [AndroidViewSurface] to build the [WebView] widget. | ||
/// | ||
/// To use this, set [WebView.platform] to an instance of this class. | ||
class SurfaceAndroidWebView extends AndroidWebView { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the AndroidManifest change required? if so we should probably mention it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is no longer required, so I removed it from the changelog and example
packages/webview_flutter/example/test_driver/webview_flutter_e2e.dart
Outdated
Show resolved
Hide resolved
This change worked well for my problem. When will the webview_flutter be updated? Thanks! |
/// This implementation uses Hybrid Composition to render the [WebView] on | ||
/// Android. It solves multiple issues related to accessibility and interaction | ||
/// with the [WebView] at the cost of some performance on Android versions below | ||
/// 10. See https://github.com/flutter/flutter/issues/61133 for more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// | ||
/// To use this, set [WebView.platform] to an instance of this class. | ||
/// | ||
/// This implementation uses Hybrid Composition to render the [WebView] on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hybrid Composition -> hybrid composition
* Add support for building `WebView` widget with Android hybrid views. To use this feature, set | ||
`WebView.platform` to an instance of `SurfaceAndroidWebView`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this (note the link to hybrid composition and example):
-
Add support for building
WebView
widget with Android hybrid views.
To use this feature, setWebView.platform
to an instance ofSurfaceAndroidWebView
. For example:class WebViewExample extends StatefulWidget { @override void initState() { super.initState(); WebView.platform = SurfaceAndroidWebView(); } @override Widget build(BuildContext context) { return WebView( initialUrl: 'https://flutter.dev', ); } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + nits
Offline chat: let's revert this PR and bump the Flutter SDK in pubspec.yaml to 1.22. |
Moved to #3067 |
…tion on Android (flutter#2883)" (flutter#3066) This reverts commit 0d7a605.
…tion on Android (flutter#2883)" (flutter#3066) This reverts commit 0d7a605.
…tion on Android (flutter#2883)" (flutter#3066) This reverts commit 0d7a605.
Related Issues
Fixes flutter/flutter#61133
Tests on stable will fail until hybrid views support moves to stable
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?