-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[webview_flutter] Adds support to listen to url changes #3313
Conversation
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error { | ||
NSURL *instance = [self urlForIdentifier:identifier error:error]; | ||
if (*error) { | ||
return nil; |
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.
Should we handle the error?
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.
The pigeon host API is calling this method, so the error should be passed back to Dart. The error in *error
could be set by the method above.
@@ -1673,46 +1707,10 @@ @implementation FWFNSObjectFlutterApiCodecReader | |||
- (nullable id)readValueOfType:(UInt8)type { | |||
switch (type) { | |||
case 128: | |||
return [FWFNSErrorData fromList:[self readValue]]; |
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.
These are removed because the class method observeValue
now returns an ObjectOrIdentifier
. When it returned an Object
, all of these were included as possible return values.
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.
iOS looks good to me
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.
(Transferring my high-level LGTM from the other PR to keep GitHub status up to date with reality.)
NavigationDelegate.fromPlatform( | ||
this.platform, { | ||
this.onNavigationRequest, | ||
this.onPageStarted, | ||
this.onPageFinished, | ||
this.onProgress, | ||
this.onWebResourceError, | ||
void Function(UrlChange change)? onUrlChange, |
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 was not added as a field of the clas because there is a chance that the field can be different from the actual value. For example, a user may set this value and then call NavigationDelegate.platform.setOnUrlChange
:
final NavigationDelegate delegate = NavigationDelegate(onUrlChange: (_) {});
delegate.platform.setUrlChange((_) {});
This is true for all the other callbacks, but changing them would be a breaking change.
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 is true for all the other callbacks, but changing them would be a breaking change.
Couldn't we replace the final fields with getters, and have the getters return the platform
version of the field, to preserve API compatibility while removing the potential for them to become out of sync?
(Doesn't need to be in this PR.)
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.
@mvanbeusekom suggested something similar by making the callback method setters in PlatformNavigationDelegate
fields instead of methods. I decided against it initially because using a method allowed us to throw an UnimplementedError
for unsupported callback methods. But we could add getters to the interface as a mix of both solutions.
This wouldn't be possible in this PR since it is something we would have to add to the platform interface first anyways.
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!
NavigationDelegate.fromPlatform( | ||
this.platform, { | ||
this.onNavigationRequest, | ||
this.onPageStarted, | ||
this.onPageFinished, | ||
this.onProgress, | ||
this.onWebResourceError, | ||
void Function(UrlChange change)? onUrlChange, |
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 is true for all the other callbacks, but changing them would be a breaking change.
Couldn't we replace the final fields with getters, and have the getters return the platform
version of the field, to preserve API compatibility while removing the potential for them to become out of sync?
(Doesn't need to be in this PR.)
flutter/packages@faf53fb...88591be 2023-04-19 [email protected] Roll Flutter from 42fb0b2 to 3476b96 (20 revisions) (flutter/packages#3760) 2023-04-19 49699333+dependabot[bot]@users.noreply.github.com Bump cirrusci/flutter from `794fbbc` to `d99b1ba` in /.ci (flutter/packages#3724) 2023-04-18 [email protected] [webview_flutter] Adds support to listen to url changes (flutter/packages#3313) 2023-04-18 [email protected] Roll Flutter from 15cb1f8 to 42fb0b2 (19 revisions) (flutter/packages#3756) 2023-04-18 49699333+dependabot[bot]@users.noreply.github.com [webview]: Bump com.android.tools.build:gradle from 7.2.2 to 8.0.0 in /packages/webview_flutter/webview_flutter_android/android (flutter/packages#3739) 2023-04-18 [email protected] [local_auth] Convert Android to Pigeon (flutter/packages#3748) 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Transfer of flutter/plugins#7113 (All the comments of that PR have been addressed in this one) 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.~~ All split PRs have been merged. This adds the `PlatformNavigationDelegate.setOnUrlChange(UrlChange)` method to track url changes. Android adds support for this with the [WebViewClient.doUpdateVisitedHistory](https://developer.android.com/reference/android/webkit/WebViewClient#doUpdateVisitedHistory(android.webkit.WebView,%20java.lang.String,%20boolean)) iOS adds support by observing the value [WKWebView.URL](https://developer.apple.com/documentation/webkit/wkwebview/1415005-url?language=objc). Since the WKWebView.URL would pass back an [NSURL](https://developer.apple.com/documentation/foundation/nsurl?language=objc) to the [observeValue](https://developer.apple.com/documentation/objectivec/nsobject/1416553-observevalueforkeypath?language=objc) 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. Fixes flutter/flutter#27729
Transfer of flutter/plugins#7113 (All the comments of that PR have been addressed in this one)
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.All split PRs have been merged.This adds the
PlatformNavigationDelegate.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 anint
or an identifier. So theObjectOrIdentifier
data class was created to handle this. Alternatives considered:NSURL
to anNSString
. This would work for this situation, but wouldn't work for a class that can't be easily converted to aString
.observeValue
callback method for returning an identifier. Potentially namedobserveIdentifier
. This doesn't work for returning a list of Objects.Fixes flutter/flutter#27729
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.