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

Conversation

EitanSchwartz
Copy link
Contributor

Description

This commit adds the following WebView functionality:
scrollTo(int x, int y), scrollBy(int x, int y), getScrollX() & getScrollY().
The new code uses Android's WebView.scrollTo() & iOS WKWebView.scrollView.contentOffset.

Related Issues

  • flutter/flutter48708
  • flutter/flutter48717
  • flutter/flutter48720

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

…ew.scrollTo & iOS WKWebView.scrollView.contentOffset.
@EitanSchwartz EitanSchwartz force-pushed the EnableProgrammaticScrollingInWebView branch from c86317c to 1f34e03 Compare February 16, 2020 12:51
…ew.scrollTo & iOS WKWebView.scrollView.contentOffset.

- Merged upstream back into branch.
Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

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

Thanks! this looks very good! Sorry for the delay in reviewing I've been swamped recently.

I mostly had formatting nits.

<script type="text/javascript">
function config() {
//make sure scrolling is enabled on both x & y.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm a little confused by the comment, is this make sure scrolling is enabled, or is it making sure that the page's content is big enough to require scrolling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for note, you're correct. Changed to: "Create a page with dimensions big enough to allow scrolling on both x & y." in coming commit.

<script type="text/javascript">
function config() {
//make sure scrolling is enabled on both x & y.
Copy link
Contributor

Choose a reason for hiding this comment

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

uber nit: missing space after the // (same for single line Dart comments below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in coming commit.

return _webViewPlatformController.getTitle();
}

/// Set the scrolled position of this view.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, thx for pointing this out. Fixed in coming commit.

}

/// Set the scrolled position of this view.
/// 'x' - the x position to scroll to.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the unit for x and y? is it the same unit across platforms?

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 the coming commit, I adjusted the comment to state pixel specifically.
I was not sure at first iOS also works in pixels but looking into it, the "point" unit they require eventually translates into pixel.

In Apple's official docs they name the unit as 'Point' and the value is translated using CGFloat but other articles proclaim that Apple rounds these points since graphical rendering cannot split pixels. Eventually it means iOS is using pixels as well.

Sources:

Additionally it looks like common working practice is to treat this input as pixels:

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!
We should emphasize that that these are pixels in the webview space (e.g these are not Flutter's logical pixels)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Amir, I'm not sure what the best phrasing is, suggesting:
"the x position, in pixels, to scroll the WebView content to."
Same for y position?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about:

/// Sets the webview's content scroll position.
///
/// The parameters `x` and `y` specify the scroll position in webview pixels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100%, Added in incoming commit.

Merge branch 'upstream_master' into EnableProgrammaticScrollingInWebView

# Conflicts:
#	AUTHORS
#	packages/webview_flutter/CHANGELOG.md
#	packages/webview_flutter/pubspec.yaml
"WebView getTitle is not implemented on the current platform");
}

/// Set the scrolled position of this view.
Copy link
Contributor

Choose a reason for hiding this comment

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

Empty line after the summary for all Dartdoc comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Same below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in incoming commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also made a pass to look for any other comments I introduced and correct this if needed.

}

/// Set the scrolled position of this view.
/// 'x' - the x position to scroll to.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!
We should emphasize that that these are pixels in the webview space (e.g these are not Flutter's logical pixels)

Copy link
Contributor

@amirh amirh left a comment

Choose a reason for hiding this comment

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

LGTM modulo some comment nits.

Thank you!

}

/// Set the scrolled position of this view.
/// 'x' - the x position to scroll to.
Copy link
Contributor

Choose a reason for hiding this comment

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

Document the unit here as well, this documentation may be the only thing a platform implementor is reading.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in incoming commit.

"WebView getTitle is not implemented on the current platform");
}

/// Set the scrolled position of this view.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same below


/// Return the horizontal scroll position of this view.
///
/// Scroll position is measured from left.
Copy link
Contributor

Choose a reason for hiding this comment

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

Mention the returned unit here and on getScrollY

Copy link
Contributor Author

@EitanSchwartz EitanSchwartz Apr 27, 2020

Choose a reason for hiding this comment

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

Added in incoming commit.

Copy link
Contributor

@amirh amirh 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!

Waiting for flutter/flutter#55743 (comment) before landing.

@amirh amirh merged commit a0b692d into flutter:master Apr 27, 2020
amirh added a commit to amirh/plugins that referenced this pull request Apr 27, 2020
EdwinRomelta pushed a commit to EdwinRomelta/plugins that referenced this pull request Jun 11, 2020
EdwinRomelta pushed a commit to EdwinRomelta/plugins that referenced this pull request Jun 11, 2020
jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants