Skip to content
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

Merged
merged 37 commits into from
Feb 9, 2024

Conversation

TheVinhLuong
Copy link
Contributor

@TheVinhLuong TheVinhLuong commented Mar 11, 2023

Description

This PR is created from the previous PR in flutter/plugin

Related Issues

flutter/flutter#31027

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/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package 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.

@TheVinhLuong
Copy link
Contributor Author

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.

@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch from e22ed48 to d91b421 Compare March 11, 2023 17:12
@reidbaker
Copy link
Contributor

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.

@TheVinhLuong
Copy link
Contributor Author

TheVinhLuong commented Apr 1, 2023

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.

@TheVinhLuong
Copy link
Contributor Author

TheVinhLuong commented Apr 1, 2023

@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 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.

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 enableContentOffsetChangedListener after all?

Copy link
Contributor

@bparrishMines bparrishMines left a 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(
Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines 20 to 23
// To ease adding additional methods, this value is added prematurely.
@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final BinaryMessenger binaryMessenger;
Copy link
Contributor

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

@@ -868,6 +875,16 @@ void main() {
verify(mockWebView.settings).called(1);
verify(mockSettings.setUserAgentString('Test Framework')).called(1);
});

test('setScrollListener', () async {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
test('setScrollListener', () async {
test('setOnContentOffsetChanged', () async {

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 decided to remove this test and instead add the integration test since this would need an actual WebView instance.

@TheVinhLuong
Copy link
Contributor Author

TheVinhLuong commented Apr 14, 2023

@bparrishMines Thanks for your thorough review. I fix it up based on your comment, please review it again.

Copy link
Contributor

@bparrishMines bparrishMines left a 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.

@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch from 5c4dfc2 to 024e3a7 Compare April 29, 2023 13:18
@TheVinhLuong
Copy link
Contributor Author

Hi @bparrishMines, could you please review this commit, thank you!

Copy link
Contributor

@stuartmorgan stuartmorgan left a 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.

@@ -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(
Copy link
Contributor

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.

@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch 2 times, most recently from c0bf3ef to 0c2fde1 Compare May 30, 2023 15:47
@bparrishMines
Copy link
Contributor

This is the aggregate PR still waiting on the implementations PR: #5664

auto-submit bot pushed a commit that referenced this pull request Feb 7, 2024
… `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.
@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch from c19a04a to 919e7b9 Compare February 9, 2024 08:35
@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch from 919e7b9 to 97ace1f Compare February 9, 2024 08:43
@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch 3 times, most recently from aa78e69 to a319981 Compare February 9, 2024 13:38
@TheVinhLuong TheVinhLuong force-pushed the webview-scroll-listener branch from a319981 to a2400d2 Compare February 9, 2024 14:11
@TheVinhLuong
Copy link
Contributor Author

@stuartmorgan Please review it again, thanks.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@stuartmorgan stuartmorgan added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 9, 2024
@auto-submit auto-submit bot merged commit b58b33c into flutter:main Feb 9, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 12, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 12, 2024
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
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
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.
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
… `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.
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
## Description
This PR is created from [the previous PR in flutter/plugin](flutter/plugins#2107)

## Related Issues
flutter/flutter#31027
bill-skdnd pushed a commit to skdnd-metaspace/webview_flutter_wkwebview that referenced this pull request Aug 2, 2024
… `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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App federated: all_changes PR that contains changes for all packages for a federated plugin change p: webview_flutter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants