Add ScrollTo support to ScrollView
This commit is contained in:
parent
27745d9d35
commit
7ee02c4b38
|
@ -5,18 +5,56 @@ using Xamarin.Forms;
|
|||
|
||||
namespace Ooui.Forms.Renderers
|
||||
{
|
||||
public class ScrollViewRenderer : ViewRenderer<ScrollView, Div>
|
||||
public class ScrollViewRenderer : VisualElementRenderer<ScrollView>
|
||||
{
|
||||
bool disposed = false;
|
||||
|
||||
protected override void OnElementChanged (ElementChangedEventArgs<ScrollView> e)
|
||||
{
|
||||
base.OnElementChanged (e);
|
||||
if (e.OldElement != null) {
|
||||
e.OldElement.ScrollToRequested -= Element_ScrollToRequested;
|
||||
}
|
||||
|
||||
this.Style.Overflow = "scroll";
|
||||
if (e.NewElement != null) {
|
||||
Style.Overflow = "scroll";
|
||||
|
||||
e.NewElement.ScrollToRequested += Element_ScrollToRequested;
|
||||
}
|
||||
|
||||
base.OnElementChanged (e);
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
base.OnElementPropertyChanged (sender, e);
|
||||
base.Dispose (disposing);
|
||||
|
||||
if (disposing && !disposed) {
|
||||
if (Element != null) {
|
||||
Element.ScrollToRequested -= Element_ScrollToRequested;
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Element_ScrollToRequested (object sender, ScrollToRequestedEventArgs e)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue