summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2017-04-17 06:39:33 (GMT)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>2017-04-17 06:39:33 (GMT)
commitb50e7e2a8a521e052ee041a704bbcfefa971d087 (patch)
tree346489425e4e6dfc62a3973f58e039412c5b3d7a
parent647f676b5ca3196d8d51318d3fbdadd4dd514a5c (diff)
parent0ba662e9f10b5e4d8509a23a507e84b851b7a9fd (diff)
downloadxamarin-forms-b50e7e2a8a521e052ee041a704bbcfefa971d087.zip
xamarin-forms-b50e7e2a8a521e052ee041a704bbcfefa971d087.tar.gz
xamarin-forms-b50e7e2a8a521e052ee041a704bbcfefa971d087.tar.bz2
Merge "Refactor layout update code" into tizen
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/Box.cs5
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs34
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs67
3 files changed, 37 insertions, 69 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Native/Box.cs b/Xamarin.Forms.Platform.Tizen/Native/Box.cs
index 9bd7bad..2f55190 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/Box.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/Box.cs
@@ -52,10 +52,7 @@ namespace Xamarin.Forms.Platform.Tizen.Native
LayoutUpdated(this, new LayoutEventArgs()
{
HasChanged = g != _previousGeometry,
- X = g.X,
- Y = g.Y,
- Width = g.Width,
- Height = g.Height,
+ Geometry = g,
}
);
}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs b/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
index 6668f8d..060a121 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
@@ -1,4 +1,5 @@
´╗┐using System;
+using ElmSharp;
namespace Xamarin.Forms.Platform.Tizen.Native
{
@@ -17,39 +18,12 @@ namespace Xamarin.Forms.Platform.Tizen.Native
}
/// <summary>
- /// X coordinate of the layout area, relative to the main window.
+ /// Geometry of the layout area, absolute coordinate
/// </summary>
- public int X
+ public Rect Geometry
{
get;
- internal set;
- }
-
- /// <summary>
- /// Y coordinate of the layout area, relative to the main window.
- /// </summary>
- public int Y
- {
- get;
- internal set;
- }
-
- /// <summary>
- /// Width of the layout area.
- /// </summary>
- public int Width
- {
- get;
- internal set;
- }
-
- /// <summary>
- /// Height of the layout area.
- /// </summary>
- public int Height
- {
- get;
- internal set;
+ set;
}
}
}
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
index 73e8c64..37e2a03 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
@@ -44,6 +44,8 @@ namespace Xamarin.Forms.Platform.Tizen
HashSet<string> _batchedProperties = new HashSet<string>();
+ int _layoutCallback = 0;
+
/// <summary>
/// Default constructor.
/// </summary>
@@ -209,10 +211,13 @@ namespace Xamarin.Forms.Platform.Tizen
public void UpdateNativeGeometry()
{
- var x = ComputeAbsoluteX(Element);
- var y = ComputeAbsoluteY(Element);
- NativeView.Geometry = new Rectangle(x, y, Element.Width, Element.Height).ToPixel();
- ApplyTransformation();
+ var updatedGeometry = new Rectangle(ComputeAbsolutePoint(Element), new Size(Element.Width, Element.Height)).ToPixel();
+
+ if (NativeView.Geometry != updatedGeometry)
+ {
+ NativeView.Geometry = updatedGeometry;
+ ApplyTransformation();
+ }
}
void IVisualElementRenderer.SetElement(VisualElement element)
@@ -250,14 +255,15 @@ namespace Xamarin.Forms.Platform.Tizen
protected virtual void UpdateLayout()
{
// we're updating the coordinates of native control only if they were modified
- // via Xamarin (Settings.IgnoreBatchCommitted is set to false);
+ // via Xamarin (IsNativeLayouting() returns false);
// otherwise native control is already in the right place
- if (!Settings.IgnoreBatchCommitted && null != NativeView)
+ if (!IsNativeLayouting() && 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)
{
@@ -291,9 +297,7 @@ namespace Xamarin.Forms.Platform.Tizen
Element.FocusChangeRequested -= OnFocusChangeRequested;
- Settings.StartIgnoringBatchCommitted();
Element.Layout(new Rectangle(0, 0, -1, -1));
- Settings.StopIgnoringBatchCommitted();
var logicalChildren = (Element as IElementController).LogicalChildren;
foreach (var child in logicalChildren)
@@ -334,9 +338,7 @@ namespace Xamarin.Forms.Platform.Tizen
e.OldElement.FocusChangeRequested -= OnFocusChangeRequested;
- Settings.StartIgnoringBatchCommitted();
Element.Layout(new Rectangle(0, 0, -1, -1));
- Settings.StopIgnoringBatchCommitted();
var controller = e.OldElement as IElementController;
if (controller != null && controller.EffectControlProvider == this)
@@ -460,9 +462,9 @@ namespace Xamarin.Forms.Platform.Tizen
{
if (_flags.HasFlag(VisualElementRendererFlags.NeedsLayout))
{
- if (!Settings.IgnoreBatchCommitted)
+ if (!IsNativeLayouting())
{
- UpdateLayout();
+ UpdateNativeGeometry();
// UpdateLayout already updates transformation, clear NeedsTranformation flag then
_flags &= ~VisualElementRendererFlags.NeedsTransformation;
}
@@ -548,19 +550,21 @@ namespace Xamarin.Forms.Platform.Tizen
protected void DoLayout(Native.LayoutEventArgs e)
{
- Settings.StartIgnoringBatchCommitted();
-
- Element.Layout(new Rectangle(Element.X, Element.Y, Forms.ConvertToScaledDP(e.Width), Forms.ConvertToScaledDP(e.Height)));
+ EnterNativeLayoutCallback();
if (e.HasChanged)
{
+ var bound = e.Geometry.ToDP();
+ bound.X = Element.X;
+ bound.Y = Element.Y;
+ Element.Layout(bound);
UpdateLayout();
}
- Settings.StopIgnoringBatchCommitted();
+ LeaveNativeLayoutCallback();
}
protected virtual Size MinimumSize()
{
- return new Size();
+ return new ESize(NativeView.MinimumWidth, NativeView.MinimumHeight).ToDP();
}
/// <summary>
@@ -606,6 +610,11 @@ namespace Xamarin.Forms.Platform.Tizen
return e.Y + (e.RealParent is VisualElement ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.Y) : 0.0);
}
+ static Point ComputeAbsolutePoint(VisualElement e)
+ {
+ return new Point(ComputeAbsoluteX(e), ComputeAbsoluteY(e));
+ }
+
/// <summary>
/// Handles focus events.
/// </summary>
@@ -995,7 +1004,6 @@ namespace Xamarin.Forms.Platform.Tizen
NativeView.EvasMap = map;
}
}
-
EFocusDirection ConvertToNativeFocusDirection(string direction) {
if (direction == XFocusDirection.Back) return EFocusDirection.Previous;
if (direction == XFocusDirection.Forward) return EFocusDirection.Next;
@@ -1006,29 +1014,18 @@ namespace Xamarin.Forms.Platform.Tizen
return EFocusDirection.Next;
}
- }
- internal static class Settings
- {
- static int s_ignoreCount = 0;
-
- public static bool IgnoreBatchCommitted
+ void EnterNativeLayoutCallback()
{
- get
- {
- return s_ignoreCount != 0;
- }
+ _layoutCallback++;
}
-
- public static void StartIgnoringBatchCommitted()
+ void LeaveNativeLayoutCallback()
{
- ++s_ignoreCount;
+ _layoutCallback--;
}
-
- public static void StopIgnoringBatchCommitted()
+ bool IsNativeLayouting()
{
- Debug.Assert(s_ignoreCount > 0);
- --s_ignoreCount;
+ return _layoutCallback > 0;
}
}
}