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

[webview_flutter_wkwebview] Implementation of PlatformNavigationDelegate for WebKit #6151

Merged
merged 24 commits into from
Aug 12, 2022

Conversation

bparrishMines
Copy link
Contributor

Part of flutter/flutter#94051

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.

@bparrishMines bparrishMines requested a review from cyanglaz as a code owner July 27, 2022 23:23
@bparrishMines bparrishMines added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Jul 27, 2022
@github-actions github-actions bot added p: webview_flutter Edits files for a webview_flutter plugin platform-ios labels Jul 27, 2022
void Function(int progress)? _onProgress;
void Function(WebResourceError error)? _onWebResourceError;
FutureOr<bool> Function({required String url, required bool isForMainFrame})?
_onNavigationRequest;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In defense of this pattern:

I wanted setters for the callbacks methods because I wanted a consistent way for a platform to indicate it doesn't support a feature.

For example, if Android doesn't support WebViewController.callSomeMethod(), it throws an UnimplementedError by default. By using setters for callback methods, the default response for a callback method is to throw an UnimplementedError. I didn't know a way to do this with a class that takes the callback methods as constructor parameters.

Also note that the app facing package will probably use fields:

class NavigationDelegate {
  final Function(String) onPageFinished;
}

But the platform classes will use setters so they can throw when a callback is not supported.

Copy link
Contributor

Choose a reason for hiding this comment

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

By using setters for callback methods, the default response for a callback method is to throw an UnimplementedError.

I think I'm missing something about the implementation; where does that happen? It looks in the code above this like the default would be a silent no-op for a null method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done in the platform interface class: https://github.com/flutter/plugins/blob/main/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_navigation_delegate.dart#L63

PlatformNavigationDelegate has to be extended, so when a new callback method is added (e.g. setOnPageRedirected) platform implementations would throw an UnimplementedError by default.

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.

LGTM

NSObject object,
Map<NSKeyValueChangeKey, Object?> change,
) {
if (weakThis.target != null && _onProgress != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can't this be weakThis.target?._onProgress != null?

@bparrishMines bparrishMines added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes autosubmit Merge PR when tree becomes green via auto submit App and removed override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Aug 12, 2022
@auto-submit auto-submit bot merged commit 7c89e38 into flutter:main Aug 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 15, 2022
moisefeelin pushed a commit to feelinproject/plugins that referenced this pull request Aug 26, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
@bparrishMines bparrishMines deleted the wkwebview_v4_navigation branch January 31, 2023 19:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: webview_flutter Edits files for a webview_flutter plugin platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants