Skip to content

Commit

Permalink
Merge pull request xamarin#9 from jsuarezruiz/gtk-force-scrollview-re…
Browse files Browse the repository at this point in the history
…sizing

ScrolledWindow needs to be resized on its parent allocation, and forc…
  • Loading branch information
jsuarezruiz authored Jun 23, 2017
2 parents 74ef361 + 110013f commit 5b2828e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion Xamarin.Forms.Platform.GTK/Renderers/ScrollViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using System;
using System.ComponentModel;
using Xamarin.Forms.Platform.GTK.Extensions;
using Xamarin.Forms.Platform.GTK.Helpers;

namespace Xamarin.Forms.Platform.GTK.Renderers
{
public class ScrollViewRenderer : ViewRenderer<ScrollView, ScrolledWindow>
{
private VisualElement _currentView;
private Viewport _viewPort;
private Gdk.Rectangle _lastAllocation;

protected IScrollViewController Controller
{
Expand Down Expand Up @@ -57,6 +57,40 @@ protected override void OnElementChanged(ElementChangedEventArgs<ScrollView> e)
}
}

protected override void OnSizeAllocated(Gdk.Rectangle allocation)
{
base.OnSizeAllocated(allocation);

if (IsAnimationRunning(Element))
{
return;
}

if (_lastAllocation != allocation)
{
_lastAllocation = allocation;

Rectangle bounds = Element.Bounds;
Container.MoveTo((int)bounds.X, (int)bounds.Y);

for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
{
var child = ElementController.LogicalChildren[i] as VisualElement;

if (child != null)
{
var renderer = Platform.GetRenderer(child);
renderer?.Container.SetSize(child.Bounds.Width, child.Bounds.Height);

if (!IsAnimationRunning(renderer.Element))
{
renderer?.Container.MoveTo(child.Bounds.X, child.Bounds.Y);
}
}
}
}
}

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
Expand Down

0 comments on commit 5b2828e

Please sign in to comment.