2018-04-16 02:29:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Ooui.Forms.Extensions;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Ooui.Forms.Renderers
|
|
|
|
|
{
|
2018-04-16 19:38:10 +00:00
|
|
|
|
public class ScrollViewRenderer : VisualElementRenderer<ScrollView>
|
2018-04-16 02:29:58 +00:00
|
|
|
|
{
|
2018-04-16 19:38:10 +00:00
|
|
|
|
bool disposed = false;
|
|
|
|
|
|
2018-04-16 02:29:58 +00:00
|
|
|
|
protected override void OnElementChanged (ElementChangedEventArgs<ScrollView> e)
|
|
|
|
|
{
|
2018-04-16 19:38:10 +00:00
|
|
|
|
if (e.OldElement != null) {
|
|
|
|
|
e.OldElement.ScrollToRequested -= Element_ScrollToRequested;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.NewElement != null) {
|
|
|
|
|
Style.Overflow = "scroll";
|
|
|
|
|
|
|
|
|
|
e.NewElement.ScrollToRequested += Element_ScrollToRequested;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-16 02:29:58 +00:00
|
|
|
|
base.OnElementChanged (e);
|
2018-04-16 19:38:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose (bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose (disposing);
|
2018-04-16 02:29:58 +00:00
|
|
|
|
|
2018-04-16 19:38:10 +00:00
|
|
|
|
if (disposing && !disposed) {
|
|
|
|
|
if (Element != null) {
|
|
|
|
|
Element.ScrollToRequested -= Element_ScrollToRequested;
|
|
|
|
|
}
|
|
|
|
|
disposed = true;
|
|
|
|
|
}
|
2018-04-16 02:29:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-16 19:38:10 +00:00
|
|
|
|
void Element_ScrollToRequested (object sender, ScrollToRequestedEventArgs e)
|
2018-04-16 02:29:58 +00:00
|
|
|
|
{
|
2018-04-16 19:38:10 +00:00
|
|
|
|
var oe = (ITemplatedItemsListScrollToRequestedEventArgs)e;
|
|
|
|
|
var item = oe.Item;
|
|
|
|
|
var group = oe.Group;
|
|
|
|
|
if (e.Mode == ScrollToMode.Position) {
|
|
|
|
|
Send (Ooui.Message.Set (Id, "scrollTop", e.ScrollY));
|
|
|
|
|
Send (Ooui.Message.Set (Id, "scrollLeft", e.ScrollX));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch (e.Position) {
|
|
|
|
|
case ScrollToPosition.Start:
|
|
|
|
|
Send (Ooui.Message.Set (Id, "scrollTop", 0));
|
|
|
|
|
break;
|
|
|
|
|
case ScrollToPosition.End:
|
|
|
|
|
Send (Ooui.Message.Set (Id, "scrollTop", new Ooui.Message.PropertyReference { TargetId = Id, Key = "scrollHeight" }));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-16 02:29:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|