-
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] Add listener for content offset #3444
[webview_flutter] Add listener for content offset #3444
Conversation
HI @bparrishMines, could you review my PR? Currently, this is an implementation for Android side only. I want to make sure the way the listener was added is correct before landing an additional commit with similar changes for the iOS. |
e22ed48
to
d91b421
Compare
packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart
Outdated
Show resolved
Hide resolved
Thank you for your contribution. It looks like you have some open comments and merge conflicts. Is this still something you plan to get to? If you are unsure how to proceed, please reach out for help on the #hackers-new channel. |
@reidbaker Ah yes, I still plan to continue working on it. |
@bparrishMines I think I get your idea. Could you take a look again at this commit to see if it is done as you want? The reason why I created Please correct me if I am wrong but with the way you wanted to implement this offset callback the platform channel will always need to carry the offset change events to the flutter side even if the users don't set the listener for it. So do you think we should retain the |
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.
@bparrishMines I think I get your idea. Could you take a look again at this commit to see if it is done as you want?
Yes this is the implementation that I was thinking. I would just update the name to match the java method name. Thanks for updating this.
The reason why I created enableContentOffsetChangedListener in the first place is because I don't want the offset listener to abuse the platform channel unnecessarily when the user doesn't set the listener. The offset changed callback will be called on many times so I think it could put a burden on the platform channel.
You're correct that this callback will lead to unnecessary use of the platform channel. This is true for every callback and I plan on addressing this in another PR. If you don't notice performance being affected by this, then I don't think it is necessary to change the design of this callback preemptively.
@@ -211,6 +211,9 @@ abstract class WebViewHostApi { | |||
abstract class WebViewFlutterApi { | |||
/// Create a new Dart instance and add it to the `InstanceManager`. | |||
void create(int identifier); | |||
|
|||
void onScrollPosChange( |
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 should be onScrollChanged
since it's the name of the Java method: https://developer.android.com/reference/android/webkit/WebView#onScrollChanged(int,%20int,%20int,%20int)
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.
You've marked this a resolved, but the name hasn't been changed.
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.
My bad, I overlooked this.
// To ease adding additional methods, this value is added prematurely. | ||
@SuppressWarnings({"unused", "FieldCanBeLocal"}) | ||
private final BinaryMessenger binaryMessenger; |
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 three lines need to be kept
...r_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java
Outdated
Show resolved
Hide resolved
...r_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java
Outdated
Show resolved
Hide resolved
...tter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_android/lib/src/android_webview_api_impls.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart
Outdated
Show resolved
Hide resolved
@@ -868,6 +875,16 @@ void main() { | |||
verify(mockWebView.settings).called(1); | |||
verify(mockSettings.setUserAgentString('Test Framework')).called(1); | |||
}); | |||
|
|||
test('setScrollListener', () async { |
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.
nit:
test('setScrollListener', () async { | |
test('setOnContentOffsetChanged', () async { |
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.
I decided to remove this test and instead add the integration test since this would need an actual WebView instance.
@bparrishMines Thanks for your thorough review. I fix it up based on your comment, please review it again. |
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 should also pull in the latest version of main. The packages have gone through some significant changes since the last review.
...iew_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart
Outdated
Show resolved
Hide resolved
...s/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart
Outdated
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart
Outdated
Show resolved
Hide resolved
.../webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart
Outdated
Show resolved
Hide resolved
5c4dfc2
to
024e3a7
Compare
Hi @bparrishMines, could you please review this commit, thank you! |
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.
Please review all the repo_test failures; there are a number of issues it's caught.
...r_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java
Outdated
Show resolved
Hide resolved
...tter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java
Outdated
Show resolved
Hide resolved
...tter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java
Outdated
Show resolved
Hide resolved
@@ -211,6 +211,9 @@ abstract class WebViewHostApi { | |||
abstract class WebViewFlutterApi { | |||
/// Create a new Dart instance and add it to the `InstanceManager`. | |||
void create(int identifier); | |||
|
|||
void onScrollPosChange( |
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.
You've marked this a resolved, but the name hasn't been changed.
c0bf3ef
to
0c2fde1
Compare
This is the aggregate PR still waiting on the implementations PR: #5664 |
… `setOnScrollPositionChange` for webview_flutter platform implementations (#5664) Adds iOS and Android implementation for content offset listener This PR is part of a series of PRs that aim to close flutter/flutter#31027. The PR that contains all changes can be found at #3444.
c19a04a
to
919e7b9
Compare
919e7b9
to
97ace1f
Compare
aa78e69
to
a319981
Compare
…pdate app-facing package's CHANGELOG
a319981
to
a2400d2
Compare
packages/webview_flutter/webview_flutter/example/ios/Runner.xcodeproj/project.pbxproj
Outdated
Show resolved
Hide resolved
..._flutter/webview_flutter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
Outdated
Show resolved
Hide resolved
@stuartmorgan Please review it again, thanks. |
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, thanks!
flutter/packages@11152d2...0a69259 2024-02-09 everythingoutdated@gmail.com [local_auth]: Renamed `local_auth_ios` to `local_auth_darwin` (flutter/packages#5809) 2024-02-09 ltv.luongthevinh@gmail.com [webview_flutter] Add listener for content offset (flutter/packages#3444) 2024-02-09 David.Chopin@wwt.com [go_router] Expose full `Uri` on `GoRouterState` in `GoRouterRedirect` (flutter/packages#5742) 2024-02-09 stuartmorgan@google.com [webview_flutter] Minor test cleanup (flutter/packages#6031) 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 flutter-ecosystem@google.com,rmistry@google.com 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
flutter#5427) Adds the platform interface implementation for content offset listener This PR is part of a series of PRs that aim to close flutter/flutter#31027. The PR that contains all changes can be found at flutter#3444.
… `setOnScrollPositionChange` for webview_flutter platform implementations (flutter#5664) Adds iOS and Android implementation for content offset listener This PR is part of a series of PRs that aim to close flutter/flutter#31027. The PR that contains all changes can be found at flutter#3444.
## Description This PR is created from [the previous PR in flutter/plugin](flutter/plugins#2107) ## Related Issues flutter/flutter#31027
… `setOnScrollPositionChange` for webview_flutter platform implementations (#5664) Adds iOS and Android implementation for content offset listener This PR is part of a series of PRs that aim to close flutter/flutter#31027. The PR that contains all changes can be found at flutter/packages#3444.
Description
This PR is created from the previous PR in flutter/plugin
Related Issues
flutter/flutter#31027
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.