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] Adds support to listen to url changes #7113

Closed
wants to merge 6 commits into from

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Feb 7, 2023

This PR follows the procedure for changing federated plugins: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins

This is the aggregate solution for flutter/flutter#27729 and is NOT intended to be submitted. This will be split into PRs for each package after approval of this PR.

This adds the PlatformNavigation.setOnUrlChange(UrlChange) method to track url changes.

Android adds support for this with the WebViewClient. doUpdateVisitedHistory

iOS adds support by observing the value WKWebView.URL. Since the WKWebView.URL would pass back an NSURL to the observeValue callback, the observeValue callback would need to distinguish the difference when returning an int or an identifier. So the ObjectOrIdentifier data class was created to handle this. Alternatives considered:

  • Convert NSURL to an NSString. This would work for this situation, but wouldn't work for a class that can't be easily converted to a String.
  • Create a separate observeValue callback method for returning an identifier. Potentially named observeIdentifier. This doesn't work for returning a list of Objects.

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-android platform-ios labels Feb 7, 2023
@bparrishMines bparrishMines changed the title Url change 2 [webview_flutter] Adds support to listen to url changes Feb 7, 2023
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 with some small nits! Feel free to start breaking out the sub PRs and we can start getting it landed.

instanceManager: _nsUrlHostApi.instanceManager,
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not something that needs action, but to file for reference as we evaluate this approach: I think NSURL is a good example of a place where hewing as close as possible to the native APIs is actually more trouble than it's worth (until/unless we have auto-generated language projections). It's essentially just a string with utility methods, and we have very similar functionality in Dart already in the form of Uri. In practice, if we passed strings over the channel instead of objects, and converted them to NSURL and Uri on the respective language sides, it would be simpler since it would eliminate object tracking for URLs, and work just as well in almost all cases. (The only example I can think of where it wouldn't would be things that can be expressed as NSURLs but not Uris, but that's very rare.)

@stuartmorgan-g
Copy link
Contributor

We've just completed the migration of the plugin code to the flutter/packages repository, as described in https://flutter.dev/go/flutter-plugins-repo-migration, and this repository is now being archived. Unfortunately that means that all in-progress PRs here must be moved to flutter/packages.

Please see our instructions for an explanation of how to move your PR, and if you have any issues moving your PR please don't hesitate to reach out in the #hackers-ecosystem channel in Discord.

Our apologies that your PR was caught in this one-time transition. We're aware that it's disruptive in the short term, and appreciate your help in getting us to a better long-term state!

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-android platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants