From 5899579b93e545dbab3d1c37adcc2bbd8148e462 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sun, 17 May 2015 22:19:13 -0500 Subject: [PATCH 01/15] Xamarin version changes --- Demo/Demo.csproj | 2 -- XibFree/XibFree.csproj | 2 -- 2 files changed, 4 deletions(-) diff --git a/Demo/Demo.csproj b/Demo/Demo.csproj index ae068f4..4cb1569 100644 --- a/Demo/Demo.csproj +++ b/Demo/Demo.csproj @@ -3,8 +3,6 @@ Debug iPhoneSimulator - 8.0.30703 - 2.0 {3AB2BCA1-4E9C-44FD-81AD-5B8F2B4F6BE0} {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe diff --git a/XibFree/XibFree.csproj b/XibFree/XibFree.csproj index e5db645..44aa508 100644 --- a/XibFree/XibFree.csproj +++ b/XibFree/XibFree.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {3CAF9EB6-5E29-40E2-8798-2DE909310CBE} {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library From 7f888b3143eb97a262e7dd233564ddc1d5e88692 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Tue, 19 May 2015 19:01:06 -0500 Subject: [PATCH 02/15] - Fix font used in % part of table examples cell (to fit on 4" phone) - Ensure total in table examples cell is always > 0 to avoid crash --- Demo/TableViewCellDemo.cs | 4 ++-- Demo/TableViewCellDemo2.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Demo/TableViewCellDemo.cs b/Demo/TableViewCellDemo.cs index 722927c..b9d2732 100644 --- a/Demo/TableViewCellDemo.cs +++ b/Demo/TableViewCellDemo.cs @@ -26,7 +26,7 @@ public override void ViewDidLoad() { var item = new Item(); item.Title = string.Format("Item {0}", i+1); - item.Total = r.Next(1000); + item.Total = r.Next(999)+1; item.Count = r.Next(item.Total); _items.Add(item); } @@ -125,7 +125,7 @@ public DemoTableViewCell() : base(UITableViewCellStyle.Default, "DemoTableViewCe BackgroundColor = UIColor.Clear, TextColor = UIColor.FromRGB(51,102,153), HighlightedTextColor = UIColor.White, - Font = UIFont.BoldSystemFontOfSize(24), + Font = UIFont.BoldSystemFontOfSize(20), TextAlignment = UITextAlignment.Right, }, LayoutParameters = new LayoutParameters() diff --git a/Demo/TableViewCellDemo2.cs b/Demo/TableViewCellDemo2.cs index e828c05..69bb4fc 100644 --- a/Demo/TableViewCellDemo2.cs +++ b/Demo/TableViewCellDemo2.cs @@ -34,7 +34,7 @@ public override void ViewDidLoad() { var item = new Item(); item.Title = string.Format("Item {0}", i+1); - item.Total = r.Next(1000); + item.Total = r.Next(999) + 1; item.Count = r.Next(item.Total); item.LongText = messages[r.Next(messages.Length)]; _items.Add(item); @@ -155,7 +155,7 @@ public DemoTableViewCell() : base(UITableViewCellStyle.Default, "DemoTableViewCe BackgroundColor = UIColor.Clear, TextColor = UIColor.FromRGB(51,102,153), HighlightedTextColor = UIColor.White, - Font = UIFont.BoldSystemFontOfSize(24), + Font = UIFont.BoldSystemFontOfSize(20), TextAlignment = UITextAlignment.Right, }, LayoutParameters = new LayoutParameters() From a865ca96d9d9d9c211a34090cda70a23205a3d4d Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Tue, 19 May 2015 23:14:00 -0500 Subject: [PATCH 03/15] Fixed Centered, Bottom, and Right alignment (via Gravity) when Padding is non-zero: layout engine was swapping width and height in view measurements. --- XibFree/LinearLayout.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/XibFree/LinearLayout.cs b/XibFree/LinearLayout.cs index b804b26..fb98d9a 100644 --- a/XibFree/LinearLayout.cs +++ b/XibFree/LinearLayout.cs @@ -494,13 +494,13 @@ private nfloat getTotalSpacing() // Helper to get the total measured height of all subviews, including all padding and margins private nfloat getTotalMeasuredHeight() { - return (nfloat)(Padding.TotalWidth() + getTotalSpacing() + SubViews.Where(x=>!x.Gone).Sum(x=>x.GetMeasuredSize().Height + x.LayoutParameters.Margins.TotalHeight())); + return (nfloat)(Padding.TotalHeight() + getTotalSpacing() + SubViews.Where(x=>!x.Gone).Sum(x=>x.GetMeasuredSize().Height + x.LayoutParameters.Margins.TotalHeight())); } // Helper to get the total measured width of all subviews, including all padding and margins private nfloat getTotalMeasuredWidth() { - return (nfloat)(Padding.TotalHeight() + getTotalSpacing() + SubViews.Where(x=>!x.Gone).Sum(x=>x.GetMeasuredSize().Width + x.LayoutParameters.Margins.TotalWidth())); + return (nfloat)(Padding.TotalWidth() + getTotalSpacing() + SubViews.Where(x=>!x.Gone).Sum(x=>x.GetMeasuredSize().Width + x.LayoutParameters.Margins.TotalWidth())); } // Helper to adjust the parent width passed down to subviews during measurement From c805b0213280f3ef01a21b9fcad5acd509b8fe12 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Wed, 20 May 2015 22:50:03 -0500 Subject: [PATCH 04/15] - Add some new extension methods - Make GetHost() public in View so we can determine where View is hosted - Create simple Hide()/Show() View methods that handles making the underlying UIViews invisible and forcing a layout --- XibFree/PublicExtensions.cs | 51 ++++++++++++++++++++++++++++++++++++- XibFree/View.cs | 29 ++++++++++++++++++++- XibFree/ViewGroup.cs | 2 +- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/XibFree/PublicExtensions.cs b/XibFree/PublicExtensions.cs index fea7939..d305f1b 100644 --- a/XibFree/PublicExtensions.cs +++ b/XibFree/PublicExtensions.cs @@ -16,6 +16,7 @@ using System; using UIKit; +using System.Collections.Generic; namespace XibFree { @@ -47,5 +48,53 @@ public static View GetLayoutRoot(this UIView view) var host = view.GetLayoutHost(); return host.Layout; } + + /// + /// Returns the top-level ViewGroup that this view is + /// a part of. Returns null if it is not under a group + /// yet. + /// + public static ViewGroup FindRootGroup(this View view) + { + ViewGroup parent = null; + while (view.Parent != null) + { + view = parent = view.Parent; + } + return parent; + } + + /// + /// Returns the top-level UIView that this view is being hosted under. + /// Returns null if not hosted. + /// + public static UIView FindRootView(this View view) + { + var vg = FindRootGroup(view); + if (vg == null) + return null; + else + return vg.GetHost().GetUIView(); + } + + /// + /// Returns all UIViews at or under the passed view. + /// + public static IEnumerable FindUIViews(this View view) + { + var views = new List(); + if (view is NativeView) + { + views.Add((view as NativeView).View); + } + else if (view is ViewGroup) + { + foreach (var child in (view as ViewGroup).SubViews) + { + views.AddRange(FindUIViews(child)); + } + } + return views; + } } -} +} \ No newline at end of file diff --git a/XibFree/View.cs b/XibFree/View.cs index a01a92d..5a0ca0f 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -75,7 +75,7 @@ public virtual LayoutParameters LayoutParameters } // Internal helper to walk the parent view hierachy and find the view that's hosting this view hierarchy - internal virtual ViewGroup.IHost GetHost() + public virtual ViewGroup.IHost GetHost() { if (_parent==null) return null; @@ -225,6 +225,33 @@ public bool Visible } } + public void Hide(bool collapsed, bool animate) + { + LayoutParameters.Visibility = (collapsed) ? Visibility.Gone : Visibility.Invisible; + ShowHide(false, animate); + } + + public void Show(bool animate) + { + LayoutParameters.Visibility = Visibility.Visible; + ShowHide(true, animate); + } + + private void ShowHide(bool show, bool animate) + { + var root = this.FindRootView(); + UIView.Animate(0.25f, delegate + { + foreach (var uiview in this.FindUIViews()) + { + uiview.Alpha = (show) ? 1.0f : 0.0f; + } + }, delegate + { + root.SetNeedsLayout(); + }); + } + public void RemoveFromSuperview() { if (Parent!=null) diff --git a/XibFree/ViewGroup.cs b/XibFree/ViewGroup.cs index 602282f..ff645a6 100644 --- a/XibFree/ViewGroup.cs +++ b/XibFree/ViewGroup.cs @@ -191,7 +191,7 @@ public void SetHost(IHost host) /// Overridden to locate the parent host for this view hierarchy /// /// The host. - internal override ViewGroup.IHost GetHost() + public override ViewGroup.IHost GetHost() { // If this view group has been parented into an actual UIView, we'll have a IHost reference // that acts as the host for all views in the hierarchy. If not, ask our parent From 430ecfaff54f136202b6a31b07dfde0d83bdd249 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sat, 23 May 2015 18:07:02 -0500 Subject: [PATCH 05/15] Horizontal center layout fix. --- XibFree/LinearLayout.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/XibFree/LinearLayout.cs b/XibFree/LinearLayout.cs index fb98d9a..ef30c41 100644 --- a/XibFree/LinearLayout.cs +++ b/XibFree/LinearLayout.cs @@ -397,9 +397,12 @@ void LayoutVertical(CGRect newPosition) x = newPosition.Right - Padding.Right - v.LayoutParameters.Margins.Right - size.Width; break; - case Gravity.CenterHorizontal: - x = (newPosition.Left + newPosition.Right)/2 - - (size.Width + v.LayoutParameters.Margins.TotalWidth())/2; + case Gravity.CenterHorizontal: + nfloat boxWidth = newPosition.Right - newPosition.Left - + Padding.TotalWidth() - v.LayoutParameters.Margins.TotalWidth(); + nfloat offsetInBox = (boxWidth - size.Width)/2; + x = newPosition.Left + Padding.Left + v.LayoutParameters.Margins.Left + + offsetInBox; break; } From 8603be0c95099c7c76649e1d08570671dd0ff362 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Wed, 27 May 2015 21:24:27 -0500 Subject: [PATCH 06/15] Extension additions/rename. --- XibFree/PublicExtensions.cs | 48 +++++++++++++++++++++++++++++++------ XibFree/View.cs | 2 +- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/XibFree/PublicExtensions.cs b/XibFree/PublicExtensions.cs index d305f1b..87aa548 100644 --- a/XibFree/PublicExtensions.cs +++ b/XibFree/PublicExtensions.cs @@ -52,10 +52,15 @@ public static View GetLayoutRoot(this UIView view) /// /// Returns the top-level ViewGroup that this view is /// a part of. Returns null if it is not under a group - /// yet. + /// yet. If view is the root, it is returned. /// public static ViewGroup FindRootGroup(this View view) { + if (view.Parent == null && view is ViewGroup) + { + return (ViewGroup)view; + } + ViewGroup parent = null; while (view.Parent != null) { @@ -68,13 +73,42 @@ public static ViewGroup FindRootGroup(this View view) /// Returns the top-level UIView that this view is being hosted under. /// Returns null if not hosted. /// - public static UIView FindRootView(this View view) + public static UIView FindRootUIView(this View view) + { + return FindRootGroup(view)?.GetHost().GetUIView(); + } + + /// + /// Returns the nearest parent ViewGroup that this view is + /// a part of. Returns null if it is not under a group + /// yet. Returns the view passed if it is actually a + /// ViewGroup. + /// + public static ViewGroup FindNearestGroup(this View view) + { + while (true) + { + if (view is ViewGroup) + { + return (ViewGroup)view; + } + view = view.Parent; + if (view == null) + { + return null; + } + } + } + + /// + /// Returns the UIView associated with nearest parent ViewGroup + /// that this view is a part of. Returns null if it is not under + /// a group yet. Returns the UIView for the view passed if it is + /// actually a ViewGroup. + /// + public static UIView FindNearestGroupUIView(this View view) { - var vg = FindRootGroup(view); - if (vg == null) - return null; - else - return vg.GetHost().GetUIView(); + return view.FindNearestGroup()?.GetHost().GetUIView(); } /// diff --git a/XibFree/View.cs b/XibFree/View.cs index 5a0ca0f..d43e292 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -239,7 +239,7 @@ public void Show(bool animate) private void ShowHide(bool show, bool animate) { - var root = this.FindRootView(); + var root = this.FindRootUIView(); UIView.Animate(0.25f, delegate { foreach (var uiview in this.FindUIViews()) From 3cddc04c344adae9c770fa28528fc7d68b32f9d4 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Fri, 29 May 2015 22:37:31 -0500 Subject: [PATCH 07/15] - Add more visibility methods to View - Work around bug whereby if Visibility is set to Gone on initial view definition --- XibFree/LinearLayout.cs | 11 ++++++++++- XibFree/PublicExtensions.cs | 2 +- XibFree/View.cs | 22 ++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/XibFree/LinearLayout.cs b/XibFree/LinearLayout.cs index ef30c41..f563517 100644 --- a/XibFree/LinearLayout.cs +++ b/XibFree/LinearLayout.cs @@ -367,7 +367,16 @@ void LayoutVertical(CGRect newPosition) // Hide hidden views if (v.Gone) { - v.Layout(CGRect.Empty, false); + try + { + v.Layout(CGRect.Empty, false); + } + catch (Exception ex) + { + // mmuegel: see exception when Visibility=Gone initially; could + // not figure it out, so this *appears* to be hack work around + System.Diagnostics.Debug.WriteLine("error laying out Gone view " + v); + } continue; } diff --git a/XibFree/PublicExtensions.cs b/XibFree/PublicExtensions.cs index 87aa548..de0ba2e 100644 --- a/XibFree/PublicExtensions.cs +++ b/XibFree/PublicExtensions.cs @@ -108,7 +108,7 @@ public static ViewGroup FindNearestGroup(this View view) /// public static UIView FindNearestGroupUIView(this View view) { - return view.FindNearestGroup()?.GetHost().GetUIView(); + return view.FindNearestGroup()?.GetHost()?.GetUIView(); } /// diff --git a/XibFree/View.cs b/XibFree/View.cs index d43e292..2f601f4 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -224,7 +224,7 @@ public bool Visible LayoutParameters.Visibility = value ? Visibility.Visible : Visibility.Invisible; } } - + public void Hide(bool collapsed, bool animate) { LayoutParameters.Visibility = (collapsed) ? Visibility.Gone : Visibility.Invisible; @@ -237,10 +237,28 @@ public void Show(bool animate) ShowHide(true, animate); } + public void SetVisibility(bool visible, bool animate) + { + if (visible) + Show(animate); + else + Hide(true, animate); + } + + public void SetVisibility(Visibility visibility, bool animate) + { + if (LayoutParameters.Visibility != visibility) + { + LayoutParameters.Visibility = visibility; + ShowHide(visibility == Visibility.Visible, animate); + } + } + private void ShowHide(bool show, bool animate) { + double delay = animate ? 0.25 : 0.0; var root = this.FindRootUIView(); - UIView.Animate(0.25f, delegate + UIView.Animate(delay, delegate { foreach (var uiview in this.FindUIViews()) { From ab586ec160a2247948d3642bc3970d9b865aa5d5 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sat, 30 May 2015 08:27:19 -0500 Subject: [PATCH 08/15] Get rid of warning. --- XibFree/LinearLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XibFree/LinearLayout.cs b/XibFree/LinearLayout.cs index f563517..f38c2bc 100644 --- a/XibFree/LinearLayout.cs +++ b/XibFree/LinearLayout.cs @@ -371,7 +371,7 @@ void LayoutVertical(CGRect newPosition) { v.Layout(CGRect.Empty, false); } - catch (Exception ex) + catch { // mmuegel: see exception when Visibility=Gone initially; could // not figure it out, so this *appears* to be hack work around From cb2caca51078e805efc3afdbbcaec511988197d8 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sat, 11 Feb 2017 16:48:54 -0600 Subject: [PATCH 09/15] Hack: disable animation delay --- XibFree/View.cs | 3 ++- XibFree/XibFree.csproj | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/XibFree/View.cs b/XibFree/View.cs index 2f601f4..a31fc69 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -256,7 +256,8 @@ public void SetVisibility(Visibility visibility, bool animate) private void ShowHide(bool show, bool animate) { - double delay = animate ? 0.25 : 0.0; + //double delay = animate ? 0.25 : 0.0; + double delay = 0; var root = this.FindRootUIView(); UIView.Animate(delay, delegate { diff --git a/XibFree/XibFree.csproj b/XibFree/XibFree.csproj index 44aa508..aac289f 100644 --- a/XibFree/XibFree.csproj +++ b/XibFree/XibFree.csproj @@ -30,7 +30,11 @@ false - + + AfterBuild + cp ${TargetFile} ${SolutionDir}/out + + true From 333e68a64a8a20ff8ffc91016ec49103706d5765 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sat, 25 Feb 2017 21:28:41 -0600 Subject: [PATCH 10/15] Improve comments --- XibFree/ViewGroup.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/XibFree/ViewGroup.cs b/XibFree/ViewGroup.cs index ff645a6..e3fce5c 100644 --- a/XibFree/ViewGroup.cs +++ b/XibFree/ViewGroup.cs @@ -67,7 +67,7 @@ public IEnumerable SubViews } /// - /// Insert a new subview at a specified position + /// Insert a new native subview at a specified position /// /// Zero-based index of where to insert the new subview. /// The native subview to insert. @@ -78,7 +78,7 @@ public void InsertSubView(int position, UIView view, LayoutParameters lp) } /// - /// Insert a new subview at the end of the subview collection + /// Insert a new native subview at the end of the subview collection /// /// The native subview to insert. /// Layout parameters for the subview. @@ -88,7 +88,7 @@ public void AddSubView(UIView view, LayoutParameters lp) } /// - /// Insert a new subview at the end of the subview collection + /// Insert a new Xib subview at the end of the subview collection /// /// The subview to add public void AddSubView(View view) @@ -97,7 +97,7 @@ public void AddSubView(View view) } /// - /// Remove a subview from the subview collection + /// Remove a native subview from the subview collection /// /// The subview to remove. public void RemoveSubView(UIView view) @@ -113,7 +113,7 @@ public void RemoveSubView(UIView view) } /// - /// Insert a new subview at a specified position + /// Insert a new Xib subview at a specified position /// /// Zero-based index of where to insert the new subview. /// The subview to add. @@ -129,7 +129,7 @@ public void InsertSubView(int position, View view) } /// - /// Remove the specified subview + /// Remove the specified Xib subview /// /// The subview to remove public void RemoveSubView(View view) @@ -138,7 +138,7 @@ public void RemoveSubView(View view) } /// - /// Remove the subview at a specified position + /// Remove the Xib subview at a specified position /// /// The zero-based index of the view to remove. public void RemoveSubViewAt(int index) From 8f481debaa777f37091386c0afc72f9bdc23a00e Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sun, 9 Apr 2017 07:52:49 -0500 Subject: [PATCH 11/15] Skill null views when setting SubViews --- XibFree/ViewGroup.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/XibFree/ViewGroup.cs b/XibFree/ViewGroup.cs index e3fce5c..c852d9f 100644 --- a/XibFree/ViewGroup.cs +++ b/XibFree/ViewGroup.cs @@ -49,6 +49,9 @@ public IEnumerable SubViews } set { + // Skip null views + value = value.Where(v => v != null); + // Check none of the child already have parents foreach (var c in value) { From 14d8dfd9b0b5814b6dc8e6b1d24d1eee6944e7da Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Mon, 10 Apr 2017 21:10:58 -0500 Subject: [PATCH 12/15] Allow visibility to be set before view is hosted. --- XibFree/PublicExtensions.cs | 2 +- XibFree/View.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/XibFree/PublicExtensions.cs b/XibFree/PublicExtensions.cs index de0ba2e..de8fcb4 100644 --- a/XibFree/PublicExtensions.cs +++ b/XibFree/PublicExtensions.cs @@ -75,7 +75,7 @@ public static ViewGroup FindRootGroup(this View view) /// public static UIView FindRootUIView(this View view) { - return FindRootGroup(view)?.GetHost().GetUIView(); + return FindRootGroup(view)?.GetHost()?.GetUIView(); } /// diff --git a/XibFree/View.cs b/XibFree/View.cs index a31fc69..dac692a 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -267,7 +267,10 @@ private void ShowHide(bool show, bool animate) } }, delegate { - root.SetNeedsLayout(); + if (root != null) + { + root.SetNeedsLayout(); + } }); } From 2a386d438c7045fd6bc32168ed9d1cc05d71fca5 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Sat, 22 Apr 2017 22:33:34 -0500 Subject: [PATCH 13/15] Fix layout issues by discarding Hide()/Show() request when already in target state (allows client code to be dumber) --- XibFree/View.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/XibFree/View.cs b/XibFree/View.cs index dac692a..14f9515 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -227,12 +227,24 @@ public bool Visible public void Hide(bool collapsed, bool animate) { + if (LayoutParameters.Visibility != Visibility.Visible) + { + // Already hidden or in progress + // Console.WriteLine("Skipping Hide: already hidden"); + return; + } LayoutParameters.Visibility = (collapsed) ? Visibility.Gone : Visibility.Invisible; ShowHide(false, animate); } public void Show(bool animate) { + if (LayoutParameters.Visibility == Visibility.Visible) + { + // Already visible or in progress + // Console.WriteLine("Skipping Show: already shown"); + return; + } LayoutParameters.Visibility = Visibility.Visible; ShowHide(true, animate); } @@ -256,21 +268,21 @@ public void SetVisibility(Visibility visibility, bool animate) private void ShowHide(bool show, bool animate) { - //double delay = animate ? 0.25 : 0.0; - double delay = 0; + //Console.WriteLine("ShowHide(show=" + show + ",animate=" + animate + ")"); + double delay = animate ? 0.25f : 0.0; + //double delay = 0; var root = this.FindRootUIView(); - UIView.Animate(delay, delegate + UIView.AnimateNotify(delay, delegate { foreach (var uiview in this.FindUIViews()) { uiview.Alpha = (show) ? 1.0f : 0.0f; } - }, delegate + }, (bool completed) => { - if (root != null) - { - root.SetNeedsLayout(); - } + //Console.WriteLine("completed=" + completed); + //root?.Superview?.SetNeedsLayout(); + root?.SetNeedsLayout(); }); } From 0c6a5542fb148ec2ace57808267a8ac6be343fd6 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Thu, 2 Nov 2017 20:06:44 -0500 Subject: [PATCH 14/15] Wrap a few automatic layout calls in try/catch --- XibFree/UILayoutHost.cs | 16 ++++++++++++---- XibFree/View.cs | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/XibFree/UILayoutHost.cs b/XibFree/UILayoutHost.cs index 92ec1b9..3dae7f0 100644 --- a/XibFree/UILayoutHost.cs +++ b/XibFree/UILayoutHost.cs @@ -17,6 +17,7 @@ using System; using UIKit; using CoreGraphics; +using System.Diagnostics; namespace XibFree { @@ -99,10 +100,17 @@ public override void LayoutSubviews() { if (_layout!=null) { - // Remeasure - _layout.Measure(Bounds.Width, Bounds.Height); - // Apply layout - _layout.Layout(Bounds, false); + try + { + // Remeasure + _layout.Measure(Bounds.Width, Bounds.Height); + // Apply layout + _layout.Layout(Bounds, false); + } + catch (Exception ex) + { + Trace.WriteLine("XibFree LayoutSubviews error: " + ex.Message); + } } } diff --git a/XibFree/View.cs b/XibFree/View.cs index 14f9515..20e1242 100644 --- a/XibFree/View.cs +++ b/XibFree/View.cs @@ -18,6 +18,7 @@ using UIKit; using CoreGraphics; using CoreAnimation; +using System.Diagnostics; namespace XibFree { @@ -100,7 +101,14 @@ internal virtual void onDetach() /// The new position of this view public void Layout(CGRect newPosition, bool parentHidden) { - onLayout(newPosition, parentHidden); + try + { + onLayout(newPosition, parentHidden); + } + catch (Exception ex) + { + Trace.WriteLine("XibFree Layout error: " + ex.Message); + } } /// From 4e15621d050d896679c5ad4f833d843e0ac38c58 Mon Sep 17 00:00:00 2001 From: Michael S Muegel Date: Tue, 23 Jul 2019 18:57:29 -0500 Subject: [PATCH 15/15] Enable profiling in Debug --- XibFree/XibFree.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/XibFree/XibFree.csproj b/XibFree/XibFree.csproj index aac289f..4f8be01 100644 --- a/XibFree/XibFree.csproj +++ b/XibFree/XibFree.csproj @@ -21,6 +21,8 @@ prompt 4 false + true + true true