summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers
diff options
context:
space:
mode:
authorSeungkeun Lee <sngn.lee@samsung.com>2017-04-12 14:30:25 +0900
committerKangho Hur <kangho.hur@samsung.com>2017-07-10 11:11:22 +0900
commit80d6ecedce6121be9f35d7bdd13d4bb1a828404c (patch)
tree4b71f4e8c37d169148bb3432937fd6fe20c1b89d /Xamarin.Forms.Platform.Tizen/Renderers
parent9b7af294d889c863a8b897425b21898a9e17c6e8 (diff)
downloadxamarin-forms-80d6ecedce6121be9f35d7bdd13d4bb1a828404c.tar.gz
xamarin-forms-80d6ecedce6121be9f35d7bdd13d4bb1a828404c.tar.bz2
xamarin-forms-80d6ecedce6121be9f35d7bdd13d4bb1a828404c.zip
Refactor layout update code
- A small refactoring - In OnBatchCommitted, Only update the Element itself location, not update children Because it is enough - Prevent duplicate update - Globally applied IgnoreBatchCommitted was changed to locally and re-named - Fixed rotation issue Change-Id: I32b57317169d81d7ad6e45f0b52eb2a8f1d861fa
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/Renderers')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs67
1 files changed, 32 insertions, 35 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
index 73e8c64f..37e2a036 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;
}
}
}