diff options
author | kingces95 <kingces95@users.noreply.github.com> | 2017-06-22 18:36:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-22 18:36:52 -0400 |
commit | 9940fc261e4325196eaf8947a2fd2bf7001160c0 (patch) | |
tree | 03cc7097c8cc9417aacd6e2bfe82f6a4ac11f3a8 /Xamarin.Forms.Core | |
parent | 075a6b370d1dce8f211264422723276411f98b85 (diff) | |
download | xamarin-forms-9940fc261e4325196eaf8947a2fd2bf7001160c0.tar.gz xamarin-forms-9940fc261e4325196eaf8947a2fd2bf7001160c0.tar.bz2 xamarin-forms-9940fc261e4325196eaf8947a2fd2bf7001160c0.zip |
Breaking; Make Grid.AddHz/Vt span ortho dim (#984)
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r-- | Xamarin.Forms.Core/Grid.cs | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/Xamarin.Forms.Core/Grid.cs b/Xamarin.Forms.Core/Grid.cs index adc239e7..4d4094cc 100644 --- a/Xamarin.Forms.Core/Grid.cs +++ b/Xamarin.Forms.Core/Grid.cs @@ -332,12 +332,14 @@ namespace Xamarin.Forms if (view == null) throw new ArgumentNullException("view"); - int lastRow = this.Any() ? this.Max(w => GetRow(w) + GetRowSpan(w) - 1) : -1; - lastRow = Math.Max(lastRow, Parent.RowDefinitions.Count - 1); - int lastCol = this.Any() ? this.Max(w => GetColumn(w) + GetColumnSpan(w) - 1) : -1; - lastCol = Math.Max(lastCol, Parent.ColumnDefinitions.Count - 1); + var rows = RowCount(); + var columns = ColumnCount(); - Add(view, lastCol + 1, lastCol + 2, 0, Math.Max(1, lastRow)); + // if no rows, create a row + if (rows == 0) + rows++; + + Add(view, columns, columns + 1, 0, rows); } public void AddVertical(IEnumerable<View> views) @@ -353,13 +355,25 @@ namespace Xamarin.Forms if (view == null) throw new ArgumentNullException("view"); - int lastRow = this.Any() ? this.Max(w => GetRow(w) + GetRowSpan(w) - 1) : -1; - lastRow = Math.Max(lastRow, Parent.RowDefinitions.Count - 1); - int lastCol = this.Any() ? this.Max(w => GetColumn(w) + GetColumnSpan(w) - 1) : -1; - lastCol = Math.Max(lastCol, Parent.ColumnDefinitions.Count - 1); + var rows = RowCount(); + var columns = ColumnCount(); + + // if no columns, create a column + if (columns == 0) + columns++; - Add(view, 0, Math.Max(1, lastCol), lastRow + 1, lastRow + 2); + Add(view, 0, columns, rows, rows + 1); } + + private int RowCount() => Math.Max( + this.Max<View, int?>(w => GetRow(w) + GetRowSpan(w)) ?? 0, + Parent.RowDefinitions.Count + ); + + private int ColumnCount() => Math.Max( + this.Max<View, int?>(w => GetColumn(w) + GetColumnSpan(w)) ?? 0, + Parent.ColumnDefinitions.Count + ); } } }
\ No newline at end of file |