Skip to content

[webview] Add macOS support in implementation package #6221

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

Merged
merged 47 commits into from
Aug 20, 2024

Conversation

stuartmorgan-g
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g commented Feb 28, 2024

Adds initial support for macOS.

Known limitations:

  • Scroll APIs are not supported, and currently throw unimplemented. Longer term we could consider JS polyfills, but we'd probably want to make them opt-in since injecting JS into every page has some risks.
  • Setting the background color doesn't work since the view structure is different on macOS. We may be able to use a layer-backed view to support this in the future.

Since many use cases don't require these features, my preference is to land this without that support, rather than blocking on having full parity, and then the specific features can be added later based on community interest (demand and/or contributions).

This requires 3.24, as 3.22 does not yet have gesture support for macOS platform views, and pushing this to users without gesture support would be very confusing.

Part of flutter/flutter#41725

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparrishMines I'm curious what you think of this approach to handle the fact that WKWebView has a different base class on iOS vs macOS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach for sharing code between the platforms. Especially the part of creating a platform agnostic WKWebView class. I can also see this working if we need to add the NSView class for macOS. Although I'm not sure how this translates for the Pigeon wrapper generator since the Dart classes would become completely generated.

const WebKitProxy({
this.createWebView = WKWebView.new,
WebKitProxy({
WebViewConstructor? createWebView,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparrishMines Unfortunately I had to make this non-const because of the Platform switch. Better ideas welcome!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to set this with a constant Function. Either by putting (Platform.isIOS ? WKWebViewIOS.new : WKWebViewMacOS.new); in a static method or a top-level function.

I've also have been waiting for this feature! : dart-lang/language#1048

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip! I've re-added the consts I removed.

Unfortunately I had to duplicate all the arguments, because I couldn't make a static function that returned Platform.isIOS ? WKWebViewIOS.new : WKWebViewMacOS.new and then call that because it still didn't want me calling the function in the const constructor, so I had to instead make it a wrapper that calls the right constructor each time, passing all the args through. (If I missed a way to make that work please let me know!)

Future<String?> getCustomUserAgent() {
return _webViewApi.getCustomUserAgentForInstances(this);
/// The iOS version of a WKWebView.
class WKWebViewIOS extends WKWebView implements UIView {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparrishMines This is the other half of how I'm handling the different parenting: the non-abstract classes are these subclasses which are different for the two platforms.

@stuartmorgan-g
Copy link
Contributor Author

This is blocked on Flutter main reporting a version number higher than 3.24 (and that change rolling into this repo).

@igor-lukyanov
Copy link

igor-lukyanov commented Aug 14, 2024

@stuartmorgan Does this mean that the branch will be merged into a future version of Flutter, not 3.24? We're looking forward to using macos webview in one of our projects, so I'm trying to understand the future of it to adjust our own expectations or start looking for a workaround. Thank you very much.

@stuartmorgan-g
Copy link
Contributor Author

Does this mean that the branch will be merged into a future version of Flutter, not 3.24?

webview_flutter is a package that's published to pub.dev, not a part of the Flutter SDK; it won't be merged into any version of Flutter.

@alterhuman
Copy link

Does this mean that the branch will be merged into a future version of Flutter, not 3.24?

webview_flutter is a package that's published to pub.dev, not a part of the Flutter SDK; it won't be merged into any version of Flutter.

@stuartmorgan they mean when will the package webview_flutter be updated with macOS support. I have the same question to prioritise feature development order in my flutter app.

@stuartmorgan-g
Copy link
Contributor Author

@stuartmorgan they mean when will the package webview_flutter be updated with macOS support.

I'm not going to assume that I know that someone means something very different from what they said, so I answered the question they actually asked.

I have the same question to prioritise feature development order in my flutter app.

It will land when it's no longer blocked; see my recent comment.

@wanjm
Copy link

wanjm commented Aug 17, 2024

This is blocked on Flutter main reporting a version number higher than 3.24 (and that change rolling into this repo).

what do you expected the version number to be on the branch main? @stuartmorgan

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 20, 2024
@auto-submit auto-submit bot merged commit 4d2d2e3 into flutter:main Aug 20, 2024
76 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 20, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 20, 2024
flutter/packages@7c1a05c...4d2d2e3

2024-08-20 [email protected] [webview] Add macOS support in implementation package (flutter/packages#6221)
2024-08-19 [email protected] Roll Flutter from a0c0453 to 6a28048 (22 revisions) (flutter/packages#7449)
2024-08-19 [email protected] [ci] Remove scorecard action (flutter/packages#7450)
2024-08-19 [email protected] [camerax] Re-land SurfaceProducer migration with fix for camera preview rotation (flutter/packages#6856)
2024-08-19 49699333+dependabot[bot]@users.noreply.github.com [camera]: Bump com.google.guava:guava from 33.2.1-android to 33.3.0-android in /packages/camera/camera_android_camerax/android (flutter/packages#7441)
2024-08-19 49699333+dependabot[bot]@users.noreply.github.com [sign_in]: Bump com.google.guava:guava from 33.2.1-android to 33.3.0-android in /packages/google_sign_in/google_sign_in_android/android (flutter/packages#7442)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Aug 29, 2024
Bump Xcode analyze minimum check version iOS 13 -> iOS 14 and macOS 12.3 -> macOS 13.

- Hit StoreKit2 deprecations. Exclude `in_app_purchase_storekit` to work around StoreKit 1 deprecation warnings.  Added a TODO to remove the exclusion when StoreKit2 is adopted (this should happen in the next few weeks) flutter/flutter#116383.
- Hit flutter/flutter#153587, fixed in #7513
- Hit flutter/flutter#125901 which was `#pragma`'d out in #6221

See related flutter/plugins#5778 and flutter/flutter#102835
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
flutter/packages@7c1a05c...4d2d2e3

2024-08-20 [email protected] [webview] Add macOS support in implementation package (flutter/packages#6221)
2024-08-19 [email protected] Roll Flutter from a0c0453 to 6a28048 (22 revisions) (flutter/packages#7449)
2024-08-19 [email protected] [ci] Remove scorecard action (flutter/packages#7450)
2024-08-19 [email protected] [camerax] Re-land SurfaceProducer migration with fix for camera preview rotation (flutter/packages#6856)
2024-08-19 49699333+dependabot[bot]@users.noreply.github.com [camera]: Bump com.google.guava:guava from 33.2.1-android to 33.3.0-android in /packages/camera/camera_android_camerax/android (flutter/packages#7441)
2024-08-19 49699333+dependabot[bot]@users.noreply.github.com [sign_in]: Bump com.google.guava:guava from 33.2.1-android to 33.3.0-android in /packages/google_sign_in/google_sign_in_android/android (flutter/packages#7442)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter platform-ios platform-macos waiting for stable update Can't be landed until functionality reaches the stable channel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants