summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen
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
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')
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs3
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/Box.cs20
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs11
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/ListView.cs2
-rw-r--r--Xamarin.Forms.Platform.Tizen/Native/SearchBar.cs33
-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
10 files changed, 89 insertions, 118 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
index 5db92394..1088d5c9 100644
--- a/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Cells/EntryCellRenderer.cs
@@ -54,17 +54,21 @@ namespace Xamarin.Forms.Platform.Tizen
entry
}
};
- layout.Parent = cell.Parent;
+ layout.Parent = cell;
layout.BindingContext = entryCell;
layout.MinimumHeightRequest = Forms.ConvertToScaledDP(pixelHeight);
- var nativeView = Platform.GetOrCreateRenderer(layout).NativeView;
+ var renderer = Platform.GetOrCreateRenderer(layout);
+ (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
+
+ var nativeView = renderer.NativeView;
nativeView.MinimumHeight = pixelHeight;
_cacheCandidate[nativeView] = layout;
nativeView.Deleted += (sender, e) =>
{
_cacheCandidate.Remove(sender as EvasObject);
};
+
return nativeView;
}
return null;
diff --git a/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs b/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
index 38062c7c..261c7173 100644
--- a/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Cells/ViewCellRenderer.cs
@@ -49,6 +49,8 @@ namespace Xamarin.Forms.Platform.Tizen
height = height > 0 ? height : FindCellContentHeight(viewCell);
renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(height);
+ (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
+
return renderer.NativeView;
}
return null;
@@ -80,6 +82,7 @@ namespace Xamarin.Forms.Platform.Tizen
{
_cacheCandidate.Remove((EvasObject)sender);
};
+ (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
return renderer.NativeView;
}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/Box.cs b/Xamarin.Forms.Platform.Tizen/Native/Box.cs
index 2f551902..e2550e1a 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/Box.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/Box.cs
@@ -40,24 +40,24 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// </remarks>
void NotifyOnLayout()
{
- var g = Geometry;
-
- if (0 == g.Width || 0 == g.Height)
- {
- // ignore irrelevant dimensions
- return;
- }
if (null != LayoutUpdated)
{
+ var g = Geometry;
+
+ if (0 == g.Width || 0 == g.Height || g == _previousGeometry)
+ {
+ // ignore irrelevant dimensions
+ return;
+ }
+
LayoutUpdated(this, new LayoutEventArgs()
{
- HasChanged = g != _previousGeometry,
Geometry = g,
}
);
- }
- _previousGeometry = g;
+ _previousGeometry = g;
+ }
}
}
}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs b/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
index 060a1212..ddad8039 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/LayoutEventArgs.cs
@@ -9,21 +9,12 @@ namespace Xamarin.Forms.Platform.Tizen.Native
public class LayoutEventArgs : EventArgs
{
/// <summary>
- /// Whether or not the dimensions have changed.
- /// </summary>
- public bool HasChanged
- {
- get;
- internal set;
- }
-
- /// <summary>
/// Geometry of the layout area, absolute coordinate
/// </summary>
public Rect Geometry
{
get;
- set;
+ internal set;
}
}
}
diff --git a/Xamarin.Forms.Platform.Tizen/Native/ListView.cs b/Xamarin.Forms.Platform.Tizen/Native/ListView.cs
index fed99101..8501df10 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/ListView.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/ListView.cs
@@ -595,6 +595,8 @@ namespace Xamarin.Forms.Platform.Tizen.Native
renderer.NativeView.MinimumHeight = Forms.ConvertToScaledPixel(element.MinimumHeightRequest);
}
+ (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated();
+
return renderer.NativeView;
}
};
diff --git a/Xamarin.Forms.Platform.Tizen/Native/SearchBar.cs b/Xamarin.Forms.Platform.Tizen/Native/SearchBar.cs
index db597ed9..42ada16e 100644
--- a/Xamarin.Forms.Platform.Tizen/Native/SearchBar.cs
+++ b/Xamarin.Forms.Platform.Tizen/Native/SearchBar.cs
@@ -399,25 +399,20 @@ namespace Xamarin.Forms.Platform.Tizen.Native
/// <param name="e">Event arguments.</param>
void SearchBarLayoutUpdated(object sender, LayoutEventArgs e)
{
- if (!e.HasChanged)
- {
- return;
- }
-
- _underlineRectangle.Geometry = new ERect(Geometry.Left + RectanglePaddingHorizontal,
- Geometry.Top + EntryPaddingVertical + EntryHeight + RectanglePaddingTop,
- Geometry.Width - (RectanglePaddingHorizontal * 2),
- RectangleHeight);
-
- _entry.Geometry = new ERect(Geometry.Left + EntryPaddingHorizontal,
- Geometry.Top + EntryPaddingVertical,
- Geometry.Width - (EntryPaddingHorizontal + (CancelButtonPaddingHorizontal * 2) + CancelButtonSize),
- EntryHeight);
-
- _cancelButton.Geometry = new ERect(Geometry.Right - CancelButtonSize - CancelButtonPaddingHorizontal,
- Geometry.Top + RectanglePaddingBottom,
- CancelButtonSize,
- CancelButtonSize);
+ _underlineRectangle.Geometry = new ERect(e.Geometry.Left + RectanglePaddingHorizontal,
+ e.Geometry.Top + EntryPaddingVertical + EntryHeight + RectanglePaddingTop,
+ e.Geometry.Width - (RectanglePaddingHorizontal * 2),
+ RectangleHeight);
+
+ _entry.Geometry = new ERect(e.Geometry.Left + EntryPaddingHorizontal,
+ e.Geometry.Top + EntryPaddingVertical,
+ e.Geometry.Width - (EntryPaddingHorizontal + (CancelButtonPaddingHorizontal * 2) + CancelButtonSize),
+ EntryHeight);
+
+ _cancelButton.Geometry = new ERect(e.Geometry.Right - CancelButtonSize - CancelButtonPaddingHorizontal,
+ e.Geometry.Top + RectanglePaddingBottom,
+ CancelButtonSize,
+ CancelButtonSize);
}
}
}
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;
- }
}
}