Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview] Start work on new ios implementation #4626

Merged
merged 16 commits into from
Feb 9, 2022

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Dec 20, 2021

Start of iOS side of: flutter/flutter#93732

Starts the Dart side of the platform specific implemention for iOS. Created WebViewCupertinoWidgetand added support for WebSettings.allowsInlineMediaPlayback and AutoMediaPlaybackPolicy. This currently has no effect on the working iOS implementation.

The branch that contained all the changes for Dart came out to about 9300 lines of code. This is the first PR to add all the api piece by piece.

No version change:
This is only the initial commit to flutter/flutter#93732 and doesn't make any changes to the current implementation.

No CHANGELOG change: Incremental unused code doesn't need to be noted in the CHANGELOG.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-ios labels Dec 20, 2021
break;
}

if (_isGreaterOrEqualVersion(await systemVersion, '10.0')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative to having this version check logic would be to only support mediaTypesRequiringUserActionForPlayback and handle calling the other methods with platform code. However, I wanted to try a solution of handling version conflicts in Dart. A future feature may require a more complex solution than a 1 liner like this one.

/// cannot change those settings dynamically later.
class WebViewConfiguration {
/// Indicates whether HTML5 videos play inline or use the native full-screen controller.
set allowsInlineMediaPlayback(bool allow) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

///
/// Use [AudiovisualMediaType.none] to indicate that no user gestures are
/// required to begin playing media.
set mediaTypesRequiringUserActionForPlayback(
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 bparrishMines changed the title start of building new ios implementation [webview_flutter_wkwebview] Start work on new ios implementationr Dec 22, 2021
@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview] Start work on new ios implementationr [webview_flutter_wkwebview] Start work on new ios implementation Dec 22, 2021
@godofredoc godofredoc changed the base branch from master to main January 6, 2022 22:40
/// Deprecated for iOS >= 10.0.
///
/// Passing false indicates the videos can play automatically.
@Deprecated(
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this code going to be entirely internal to the package? We shouldn't deprecate our internal wrappers when we know we'll be using them.

throw UnimplementedError();
}

/// Deprecated for iOS >= 9.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

That's all we support now, so this is dead code. We just never cleaned up the implementation after changing the min version (I guess we missed it in the scrub).

/// app’s interface. For example, if your UI includes forward and back buttons,
/// connect those buttons to the [goBack] and [goForward] methods of your web
/// view to trigger the corresponding web navigation. Use the [canGoBack] and
/// [canGoForward] fields to determine when to enable or disable your buttons.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not be duplicating docs wholesale from Apple code.

I would much prefer we say something like:
"Wraps WKWebView. See insert-link-here for documentation".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was back and forth about to what extent we should document these classes. I think this is a good pattern moving forward. I think this would also pair well with testing that links are up to date. I created an issue for it: flutter/flutter#96974


/// The system version of the iOS device.
///
/// If null, this value is retrieved asynchronously.
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation seems confusing; AFAICT is is describing what clients of this code might do, not anything this class does.

/// If null, this value is retrieved asynchronously.
final FutureOr<String>? systemVersion;

/// The handler for constructing [web_kit.WebView]s.
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's for creating webviews, isn't it a Factory rather than a Proxy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On Android, this class is also used to call static methods. So there is a possibility that it could be used for more than constructing WebViews. I updated the documentation.

@@ -16,13 +16,17 @@ flutter:
pluginClass: FLTWebViewFlutterPlugin

dependencies:
device_info_plus: ^3.1.1
Copy link
Contributor

Choose a reason for hiding this comment

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

I definitely don't want to do this. We should build the specific functionality we need into the plugin.

return _parseVersion(first).compareTo(_parseVersion(second)) >= 0;
}

Version _parseVersion(String versionStr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

pub_semver is overkill here; you're already writing manual parsing code anyway, and the set of things it needs to support is smaller than pub_semver (there's no iOS 10.0.7+3-dev for instance). You can eliminate the dependency and just parse to a three-element array then compare in a loop.

if (requiresUserAction) web_kit.AudiovisualMediaType.all,
if (!requiresUserAction) web_kit.AudiovisualMediaType.none
};
} else if (_isGreaterOrEqualVersion(await systemVersion, '9.0')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is always true, so should just be the else.

@bparrishMines
Copy link
Contributor Author

@stuartmorgan This is ready for another review. I decided to remove the logic for checking the version since it can be easily handled with platform code: https://github.com/flutter/plugins/blob/main/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FlutterWebView.m#L568

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Sorry this took forever to re-review :( LGTM with some small nits.

///
/// Wraps
/// [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview?language=objc).
class WebView {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should actually keep the WK prefix on these? It's not standard Dart, but it would make it very clear that these are just mirroring the corresponding ObjC class.

I could go either way on it, but I thought it was worth raising.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea. I added WK to all the webkit classes.

import 'web_kit/web_kit.dart' as web_kit;

/// A [Widget] that displays a [web_kit.WebView].
class WebViewCupertinoWidget extends StatefulWidget {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably not call this Cupertino since we'll likely add macOS support to this package at some point, and in Flutter terminology Cupertino is specifically iOS. WKWebViewWidget? Although that could be confusing, especially if we put WK on the other classes. How about WebViewWebKitWidget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used Cupertino because it is used as the name of the WebViewPlatform implementation, but I think we should also update that with the new plugin interface. What are your thoughts on WebKitWebViewWidget? I was also, coincidently, updating the Android implementation to AndroidWebKitWebViewWidget.

This also made me consider that this plugin is called webview_flutter_wkwebview, but the Apple library is called WebKit and WKWebView is only a class in the library. However, the Android library could technically be called WebKit too, so I could understand why are plugin naming scheme wouldn't be consistent.

But all in all, I was considering

Platform Platform Implementation Prefix Library File Name
iOS/MacOS WebKit... web_kit.dart
Android AndroidWebKit... android_web_kit.dart

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 WKWebView because it's less ambiguous; webkit doesn't really say much if you don't know its intended to be a library name. UIWebView was also WebKit-based, for instance. While WKWebView is only one class, it's the core class, with all the others being supporting classes.

}

/// An implementation of [WebViewPlatformController] with the WebKit api.
class WebViewCupertinoPlatformController extends WebViewPlatformController {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same name change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

conversation continued in #4626 (comment)

@bparrishMines bparrishMines added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Feb 9, 2022
@bparrishMines bparrishMines merged commit f2944b5 into flutter:main Feb 9, 2022
@bparrishMines bparrishMines deleted the dart_start_webview_small branch February 9, 2022 18:25
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: webview_flutter Edits files for a webview_flutter plugin platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants