-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter] Enable WebView programmatic scrolling. #2533
[webview_flutter] Enable WebView programmatic scrolling. #2533
Conversation
…ew.scrollTo & iOS WKWebView.scrollView.contentOffset.
c86317c
to
1f34e03
Compare
…ew.scrollTo & iOS WKWebView.scrollView.contentOffset. - Merged upstream back into branch.
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.
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. |
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: 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?
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.
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. |
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.
uber nit: missing space after the //
(same for single line Dart comments below)
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.
Fixed in coming commit.
return _webViewPlatformController.getTitle(); | ||
} | ||
|
||
/// Set the scrolled position of this view. |
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: empty line after the summary for all Dartdoc comments.
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.
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. |
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.
What is the unit for x
and y
? is it the same unit across platforms?
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.
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:
- https://developer.apple.com/documentation/uikit/uiscrollview/1619404-contentoffset
- http://andrewmarinov.com/uiscrollviews-contentoffset-precision/
Additionally it looks like common working practice is to treat this input as pixels:
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.
Thanks!
We should emphasize that that these are pixels in the webview space (e.g these are not Flutter's logical pixels)
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.
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?
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.
What do you think about:
/// Sets the webview's content scroll position.
///
/// The parameters `x` and `y` specify the scroll position in webview pixels.
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.
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. |
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.
Empty line after the summary for all Dartdoc comments
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.
Same below
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.
Added in incoming commit.
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.
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. |
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.
Thanks!
We should emphasize that that these are pixels in the webview space (e.g these are not Flutter's logical pixels)
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 modulo some comment nits.
Thank you!
} | ||
|
||
/// Set the scrolled position of this view. | ||
/// 'x' - the x position to scroll to. |
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.
Document the unit here as well, this documentation may be the only thing a platform implementor is reading.
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.
Same below
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.
Added in incoming commit.
"WebView getTitle is not implemented on the current platform"); | ||
} | ||
|
||
/// Set the scrolled position of this view. |
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.
Same below
|
||
/// Return the horizontal scroll position of this view. | ||
/// | ||
/// Scroll position is measured from left. |
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.
Mention the returned unit here and on getScrollY
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.
Added in incoming commit.
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!
Waiting for flutter/flutter#55743 (comment) before landing.
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
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.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?