summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers
diff options
context:
space:
mode:
authorPiotr Bereza <p.bereza@samsung.com>2017-03-22 16:45:27 +0100
committerKangho Hur <kangho.hur@samsung.com>2017-07-10 11:11:24 +0900
commit2ba80f571a23077142b14b703bdc3378b879df02 (patch)
treed6052b28af80e35d4132cea7d6ee0b00e8de38f4 /Xamarin.Forms.Platform.Tizen/Renderers
parent649baa2d3d9021f5fff50dc24c4b0d0f25fa4fa5 (diff)
downloadxamarin-forms-2ba80f571a23077142b14b703bdc3378b879df02.tar.gz
xamarin-forms-2ba80f571a23077142b14b703bdc3378b879df02.tar.bz2
xamarin-forms-2ba80f571a23077142b14b703bdc3378b879df02.zip
New way of layout
Change-Id: I827d199fdc9be0f62a2a149ed2bd943c5ab76056 Signed-off-by: Piotr Bereza <p.bereza@samsung.com>
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs6
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/FrameRenderer.cs54
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs17
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs53
4 files changed, 53 insertions, 77 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs
index c4f79653..81a00a41 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs
@@ -43,6 +43,11 @@ namespace Xamarin.Forms.Platform.Tizen
_page.Color = Element.BackgroundColor.ToNative();
}
+ protected override void UpdateLayout()
+ {
+ // empty on purpose
+ }
+
void UpdateBackgroundImage()
{
if (string.IsNullOrWhiteSpace(Element.BackgroundImage))
@@ -62,4 +67,3 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
}
-
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/FrameRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/FrameRenderer.cs
index 0684c4ac..0c815772 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/FrameRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/FrameRenderer.cs
@@ -49,34 +49,7 @@ namespace Xamarin.Forms.Platform.Tizen
base.OnElementChanged(e);
}
- void OnLayoutUpdated(object sender, Native.LayoutEventArgs e)
- {
- UpdateGeometry();
- // TODO: why is this DoLayout() required?
- if (Element.Content != null)
- base.DoLayout(e);
- }
-
- void UpdateGeometry()
- {
- var geometry = NativeView.Geometry;
- DrawFrame(_frame,
- geometry.X,
- geometry.Y,
- geometry.Right,
- geometry.Bottom,
- _thickness
- );
- DrawFrame(_shadow,
- geometry.X + _shadow_shift,
- geometry.Y + _shadow_shift,
- geometry.Right - _thickness + _shadow_shift + _shadow_thickness,
- geometry.Bottom - _thickness + _shadow_shift + _shadow_thickness,
- _shadow_thickness
- );
- }
-
- void DrawFrame(Polygon frame, int left, int top, int right, int bottom, int thickness)
+ static void DrawFrame(Polygon frame, int left, int top, int right, int bottom, int thickness)
{
frame.ClearPoints();
if (left + thickness >= right || top + thickness >= bottom)
@@ -104,6 +77,30 @@ namespace Xamarin.Forms.Platform.Tizen
frame.AddPoint(left, top + thickness);
}
+ void OnLayoutUpdated(object sender, Native.LayoutEventArgs e)
+ {
+ UpdateGeometry();
+ }
+
+ void UpdateGeometry()
+ {
+ var geometry = NativeView.Geometry;
+ DrawFrame(_frame,
+ geometry.X,
+ geometry.Y,
+ geometry.Right,
+ geometry.Bottom,
+ _thickness
+ );
+ DrawFrame(_shadow,
+ geometry.X + _shadow_shift,
+ geometry.Y + _shadow_shift,
+ geometry.Right - _thickness + _shadow_shift + _shadow_thickness,
+ geometry.Bottom - _thickness + _shadow_shift + _shadow_thickness,
+ _shadow_thickness
+ );
+ }
+
void UpdateColor()
{
if (Element.OutlineColor.IsDefault)
@@ -119,6 +116,5 @@ namespace Xamarin.Forms.Platform.Tizen
else
_shadow.Hide();
}
-
}
}
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs
index bf36afa4..2f723f3e 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/LayoutRenderer.cs
@@ -7,6 +7,8 @@ namespace Xamarin.Forms.Platform.Tizen
/// </summary>
public class LayoutRenderer : ViewRenderer<Layout, Native.Canvas>
{
+ bool _isLayoutUpdatedRegistered = false;
+
/// <summary>
/// Default constructor.
/// </summary>
@@ -14,12 +16,20 @@ namespace Xamarin.Forms.Platform.Tizen
{
}
+ public void RegisterOnLayoutUpdated()
+ {
+ if (!_isLayoutUpdatedRegistered)
+ {
+ Control.LayoutUpdated += OnLayoutUpdated;
+ _isLayoutUpdatedRegistered = true;
+ }
+ }
+
protected override void OnElementChanged(ElementChangedEventArgs<Layout> e)
{
if (null == Control)
{
var canvas = new Native.Canvas(Forms.Context.MainWindow);
- canvas.LayoutUpdated += OnLayoutUpdated;
SetNativeControl(canvas);
}
@@ -28,7 +38,10 @@ namespace Xamarin.Forms.Platform.Tizen
protected override void Dispose(bool disposing)
{
- Control.LayoutUpdated -= OnLayoutUpdated;
+ if (_isLayoutUpdatedRegistered)
+ {
+ Control.LayoutUpdated -= OnLayoutUpdated;
+ }
base.Dispose(disposing);
}
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
index 978a5b5a..a3282a3f 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
@@ -45,9 +45,7 @@ namespace Xamarin.Forms.Platform.Tizen
HashSet<string> _batchedProperties = new HashSet<string>();
- int _layoutCallback = 0;
bool _movedCallbackEnabled = false;
-
/// <summary>
/// Default constructor.
/// </summary>
@@ -257,21 +255,10 @@ namespace Xamarin.Forms.Platform.Tizen
protected virtual void UpdateLayout()
{
- // we're updating the coordinates of native control only if they were modified
- // via Xamarin (IsNativeLayouting() returns false);
- // otherwise native control is already in the right place
- if (!IsNativeLayouting() && null != NativeView)
+ if (null != NativeView)
{
UpdateNativeGeometry();
}
-
- // we're updating just immediate children
- // To update the relative postion of children
- var logicalChildren = (Element as IElementController).LogicalChildren;
- foreach (var child in logicalChildren)
- {
- Platform.GetRenderer(child)?.UpdateNativeGeometry();
- }
}
/// <summary>
@@ -471,12 +458,10 @@ namespace Xamarin.Forms.Platform.Tizen
{
if (_flags.HasFlag(VisualElementRendererFlags.NeedsLayout))
{
- if (!IsNativeLayouting())
- {
- UpdateNativeGeometry();
- // UpdateLayout already updates transformation, clear NeedsTranformation flag then
- _flags &= ~VisualElementRendererFlags.NeedsTransformation;
- }
+ UpdateLayout();
+ // UpdateLayout already updates transformation, clear NeedsTranformation flag then
+ _flags &= ~VisualElementRendererFlags.NeedsTransformation;
+
_flags ^= VisualElementRendererFlags.NeedsLayout;
}
if (_flags.HasFlag(VisualElementRendererFlags.NeedsTransformation))
@@ -559,16 +544,7 @@ namespace Xamarin.Forms.Platform.Tizen
protected void DoLayout(Native.LayoutEventArgs e)
{
- EnterNativeLayoutCallback();
- if (e.HasChanged)
- {
- var bound = e.Geometry.ToDP();
- bound.X = Element.X;
- bound.Y = Element.Y;
- Element.Layout(bound);
- UpdateLayout();
- }
- LeaveNativeLayoutCallback();
+ Element.Layout(e.Geometry.ToDP());
}
protected virtual Size MinimumSize()
@@ -611,12 +587,12 @@ namespace Xamarin.Forms.Platform.Tizen
static double ComputeAbsoluteX(VisualElement e)
{
- return e.X + (e.RealParent is VisualElement ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.X) : 0.0);
+ return e.X + ((e.RealParent is VisualElement) && !(e.RealParent is ListView) ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.X) : 0.0);
}
static double ComputeAbsoluteY(VisualElement e)
{
- return e.Y + (e.RealParent is VisualElement ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.Y) : 0.0);
+ return e.Y + ((e.RealParent is VisualElement) && !(e.RealParent is ListView) ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.Y) : 0.0);
}
static Point ComputeAbsolutePoint(VisualElement e)
@@ -1049,18 +1025,5 @@ namespace Xamarin.Forms.Platform.Tizen
return EFocusDirection.Next;
}
-
- void EnterNativeLayoutCallback()
- {
- _layoutCallback++;
- }
- void LeaveNativeLayoutCallback()
- {
- _layoutCallback--;
- }
- bool IsNativeLayouting()
- {
- return _layoutCallback > 0;
- }
}
}