diff options
author | adrianknight89 <adrianknight89@outlook.com> | 2016-12-06 06:07:29 -0600 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-12-06 12:07:29 +0000 |
commit | 9dff4c16508452512c5faa36788f65ba6419170e (patch) | |
tree | c10ba4ce6c728e953bf0d94f063cd280197a9c31 /Xamarin.Forms.Platform.Android | |
parent | 331a7b76db5bc645852b8d50a443f5a205a860d3 (diff) | |
download | xamarin-forms-9dff4c16508452512c5faa36788f65ba6419170e.tar.gz xamarin-forms-9dff4c16508452512c5faa36788f65ba6419170e.tar.bz2 xamarin-forms-9dff4c16508452512c5faa36788f65ba6419170e.zip |
[Android] ScrollView should send correct ScrollX and ScrollY (#394)
* Android should show correct ScrollX and ScrollY when scrolling in both directions
* Adding sample code to demonstrate scrolling
* Orientation fix
* ScrollTo should work for horizontal + vertical scrolling
* Get correct scroll x and y values for ScrollOrientation.Both
* Convert positions to pixels
* Adding unit test to watch out for incorrect animation positioning
* automated test
* improvements
* fixed texts
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs index 2f66d8e8..6db51c23 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ScrollViewRenderer.cs @@ -202,7 +202,18 @@ namespace Xamarin.Forms.Platform.Android internal void UpdateScrollPosition(double x, double y) { if (_view != null) + { + if (_view.Orientation == ScrollOrientation.Both) + { + if (x == 0) + x = Forms.Context.FromPixels(_hScrollView.ScrollX); + + if (y == 0) + y = Forms.Context.FromPixels(ScrollY); + } + Controller.SetScrolledPosition(x, y); + } } static int GetDistance(double start, double position, double v) @@ -248,8 +259,8 @@ namespace Xamarin.Forms.Platform.Android var x = (int)Forms.Context.ToPixels(e.ScrollX); var y = (int)Forms.Context.ToPixels(e.ScrollY); - int currentX = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollX : ScrollX; - int currentY = _view.Orientation == ScrollOrientation.Horizontal ? _hScrollView.ScrollY : ScrollY; + int currentX = _view.Orientation == ScrollOrientation.Horizontal || _view.Orientation == ScrollOrientation.Both ? _hScrollView.ScrollX : ScrollX; + int currentY = _view.Orientation == ScrollOrientation.Vertical || _view.Orientation == ScrollOrientation.Both ? ScrollY : _hScrollView.ScrollY; if (e.Mode == ScrollToMode.Element) { Point itemPosition = Controller.GetScrollPositionForElement(e.Element as VisualElement, e.Position); @@ -275,10 +286,19 @@ namespace Xamarin.Forms.Platform.Android return; } - if (_view.Orientation == ScrollOrientation.Horizontal) - _hScrollView.ScrollTo(distX, distY); - else - ScrollTo(distX, distY); + switch (_view.Orientation) + { + case ScrollOrientation.Horizontal: + _hScrollView.ScrollTo(distX, distY); + break; + case ScrollOrientation.Vertical: + ScrollTo(distX, distY); + break; + default: + _hScrollView.ScrollTo(distX, distY); + ScrollTo(distX, distY); + break; + } }; animator.AnimationEnd += delegate { @@ -291,10 +311,19 @@ namespace Xamarin.Forms.Platform.Android } else { - if (_view.Orientation == ScrollOrientation.Horizontal) - _hScrollView.ScrollTo(x, y); - else - ScrollTo(x, y); + switch (_view.Orientation) + { + case ScrollOrientation.Horizontal: + _hScrollView.ScrollTo(x, y); + break; + case ScrollOrientation.Vertical: + ScrollTo(x, y); + break; + default: + _hScrollView.ScrollTo(x, y); + ScrollTo(x, y); + break; + } Controller.SendScrollFinished(); } } |