diff --git a/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs index e858f0bd7cc..c35e90426e0 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs @@ -23,8 +23,8 @@ protected override void UpdateItemsSource() // But for the Carousel, we want it to create the items to fit the width/height of the viewport // So we give it an alternate delegate for creating the views - ItemsViewAdapter = new ItemsViewAdapter(ItemsView, Context, - (renderer, context) => new SizedItemContentControl(renderer, context, () => Width, () => Height)); + ItemsViewAdapter = new ItemsViewAdapter(ItemsView, + (renderer, context) => new SizedItemContentView(renderer, context, () => Width, () => Height)); SwapAdapter(ItemsViewAdapter, false); } diff --git a/Xamarin.Forms.Platform.Android/CollectionView/EmptyViewAdapter.cs b/Xamarin.Forms.Platform.Android/CollectionView/EmptyViewAdapter.cs index 375ddf0bfe9..a464ad120d7 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/EmptyViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/EmptyViewAdapter.cs @@ -47,14 +47,15 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int } // EmptyView is a Forms View; display that - var itemContentControl = new SizedItemContentControl(CreateRenderer(formsView, context), context, + var itemContentControl = new SizedItemContentView(CreateRenderer(formsView, context), context, () => parent.Width, () => parent.Height); return new EmptyViewHolder(itemContentControl, formsView); } // We have a template, so create a view from it var templateElement = EmptyViewTemplate.CreateContent() as View; - var templatedItemContentControl = new SizedItemContentControl(CreateRenderer(templateElement, context), context, () => parent.Width, () => parent.Height); + var templatedItemContentControl = new SizedItemContentView(CreateRenderer(templateElement, context), + context, () => parent.Width, () => parent.Height); return new EmptyViewHolder(templatedItemContentControl, templateElement); } diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemContentControl.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemContentControl.cs deleted file mode 100644 index 8d83147309d..00000000000 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemContentControl.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Android.Content; -using Android.Views; - -namespace Xamarin.Forms.Platform.Android -{ - internal class ItemContentControl : ViewGroup - { - protected readonly IVisualElementRenderer Content; - - public ItemContentControl(IVisualElementRenderer content, Context context) : base(context) - { - Content = content; - AddContent(); - } - - void AddContent() - { - AddView(Content.View); - } - - protected override void OnLayout(bool changed, int l, int t, int r, int b) - { - var size = Context.FromPixels(r - l, b - t); - - Content.Element.Layout(new Rectangle(Point.Zero, size)); - - Content.UpdateLayout(); - } - - protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) - { - int width = MeasureSpec.GetSize(widthMeasureSpec); - int height = MeasureSpec.GetSize(heightMeasureSpec); - - var pixelWidth = Context.FromPixels(width); - var pixelHeight = Context.FromPixels(height); - - SizeRequest measure = Content.Element.Measure(pixelWidth, pixelHeight, MeasureFlags.IncludeMargins); - - width = (int)Context.ToPixels(Content.Element.Width > 0 - ? Content.Element.Width : measure.Request.Width); - - height = (int)Context.ToPixels(Content.Element.Height > 0 - ? Content.Element.Height : measure.Request.Height); - - SetMeasuredDimension(width, height); - } - } -} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemContentView.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemContentView.cs new file mode 100644 index 00000000000..2f95d0c1492 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemContentView.cs @@ -0,0 +1,57 @@ +using Android.Content; +using Android.Views; + +namespace Xamarin.Forms.Platform.Android +{ + internal class ItemContentView : ViewGroup + { + protected readonly IVisualElementRenderer Content; + + public ItemContentView(IVisualElementRenderer content, Context context) : base(context) + { + Content = content; + AddContent(); + } + + void AddContent() + { + AddView(Content.View); + } + + protected override void OnLayout(bool changed, int l, int t, int r, int b) + { + var size = Context.FromPixels(r - l, b - t); + + Content.Element.Layout(new Rectangle(Point.Zero, size)); + + Content.UpdateLayout(); + } + + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + int pixelWidth = MeasureSpec.GetSize(widthMeasureSpec); + int pixelHeight = MeasureSpec.GetSize(heightMeasureSpec); + + var width = Context.FromPixels(pixelWidth); + var height = Context.FromPixels(pixelHeight); + + SizeRequest measure = Content.Element.Measure(width, height, MeasureFlags.IncludeMargins); + + if (pixelWidth == 0) + { + pixelWidth = (int)Context.ToPixels(Content.Element.Width > 0 + ? Content.Element.Width + : measure.Request.Width); + } + + if (pixelHeight == 0) + { + pixelHeight = (int)Context.ToPixels(Content.Element.Height > 0 + ? Content.Element.Height + : measure.Request.Height); + } + + SetMeasuredDimension(pixelWidth, pixelHeight); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs index 9d02403d23c..3b416b223d2 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs @@ -16,23 +16,20 @@ namespace Xamarin.Forms.Platform.Android public class ItemsViewAdapter : RecyclerView.Adapter { protected readonly ItemsView ItemsView; - readonly Context _context; readonly Func _createView; readonly IItemsViewSource _itemsSource; - internal ItemsViewAdapter(ItemsView itemsView, Context context, - Func createView = null) + internal ItemsViewAdapter(ItemsView itemsView, Func createView = null) { CollectionView.VerifyCollectionViewFlagEnabled(nameof(ItemsViewAdapter)); ItemsView = itemsView; - _context = context; _createView = createView; _itemsSource = ItemsSourceFactory.Create(itemsView.ItemsSource, this); if (_createView == null) { - _createView = (renderer, context1) => new ItemContentControl(renderer, context1); + _createView = (renderer, context) => new ItemContentView(renderer, context); } } diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs index cdfdf53108f..8751ad0f354 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs @@ -221,7 +221,7 @@ protected virtual void UpdateItemsSource() // Stop watching the old adapter to see if it's empty (if we _are_ watching) Unwatch(GetAdapter()); - ItemsViewAdapter = new ItemsViewAdapter(ItemsView, Context); + ItemsViewAdapter = new ItemsViewAdapter(ItemsView); SwapAdapter(ItemsViewAdapter, false); UpdateEmptyView(); diff --git a/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentControl.cs b/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentControl.cs deleted file mode 100644 index 5a573251a6e..00000000000 --- a/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentControl.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Android.Content; - -namespace Xamarin.Forms.Platform.Android -{ - internal class SizedItemContentControl : ItemContentControl - { - readonly Func _width; - readonly Func _height; - - public SizedItemContentControl(IVisualElementRenderer content, Context context, Func width, Func height) - : base(content, context) - { - _width = width; - _height = height; - } - - protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) - { - var pixelWidth = _width(); - var pixelHeight =_height(); - - Content.Element.Measure(pixelWidth, pixelHeight, MeasureFlags.IncludeMargins); - SetMeasuredDimension(pixelWidth, pixelHeight); - } - } -} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentView.cs b/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentView.cs new file mode 100644 index 00000000000..1964b424a71 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentView.cs @@ -0,0 +1,29 @@ +using System; +using Android.Content; + +namespace Xamarin.Forms.Platform.Android +{ + internal class SizedItemContentView : ItemContentView + { + readonly Func _width; + readonly Func _height; + + public SizedItemContentView(IVisualElementRenderer content, Context context, Func width, Func height) + : base(content, context) + { + _width = width; + _height = height; + } + + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + var targetWidth = _width(); + var targetHeight = _height(); + + Content.Element.Measure(Context.FromPixels(targetWidth), Context.FromPixels(targetHeight), + MeasureFlags.IncludeMargins); + + SetMeasuredDimension(targetWidth, targetHeight); + } + } +} diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj index e5b63cc3039..c5fa1471424 100644 --- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj +++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj @@ -82,7 +82,7 @@ - + @@ -90,7 +90,7 @@ - + diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/CollectionViewController.cs b/Xamarin.Forms.Platform.iOS/CollectionView/CollectionViewController.cs index 8b5c38c3f53..72b941d5acc 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/CollectionViewController.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/CollectionViewController.cs @@ -139,13 +139,13 @@ string DetermineCellReusedId() if (_itemsView.ItemTemplate != null) { return _layout.ScrollDirection == UICollectionViewScrollDirection.Horizontal - ? TemplatedHorizontalListCell.ReuseId - : TemplatedVerticalListCell.ReuseId; + ? HorizontalTemplatedCell.ReuseId + : VerticalTemplatedCell.ReuseId; } return _layout.ScrollDirection == UICollectionViewScrollDirection.Horizontal - ? DefaultHorizontalListCell.ReuseId - : DefaultVerticalListCell.ReuseId; + ? HorizontalDefaultCell.ReuseId + : VerticalDefaultCell.ReuseId; } UICollectionViewCell GetPrototype() @@ -162,11 +162,11 @@ UICollectionViewCell GetPrototype() void RegisterCells() { - CollectionView.RegisterClassForCell(typeof(DefaultHorizontalListCell), DefaultHorizontalListCell.ReuseId); - CollectionView.RegisterClassForCell(typeof(DefaultVerticalListCell), DefaultVerticalListCell.ReuseId); - CollectionView.RegisterClassForCell(typeof(TemplatedHorizontalListCell), - TemplatedHorizontalListCell.ReuseId); - CollectionView.RegisterClassForCell(typeof(TemplatedVerticalListCell), TemplatedVerticalListCell.ReuseId); + CollectionView.RegisterClassForCell(typeof(HorizontalDefaultCell), HorizontalDefaultCell.ReuseId); + CollectionView.RegisterClassForCell(typeof(VerticalDefaultCell), VerticalDefaultCell.ReuseId); + CollectionView.RegisterClassForCell(typeof(HorizontalTemplatedCell), + HorizontalTemplatedCell.ReuseId); + CollectionView.RegisterClassForCell(typeof(VerticalTemplatedCell), VerticalTemplatedCell.ReuseId); } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/DefaultHorizontalListCell.cs b/Xamarin.Forms.Platform.iOS/CollectionView/HorizontalDefaultCell.cs similarity index 66% rename from Xamarin.Forms.Platform.iOS/CollectionView/DefaultHorizontalListCell.cs rename to Xamarin.Forms.Platform.iOS/CollectionView/HorizontalDefaultCell.cs index 4e165b46363..5ee488746c8 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/DefaultHorizontalListCell.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/HorizontalDefaultCell.cs @@ -3,13 +3,12 @@ namespace Xamarin.Forms.Platform.iOS { - // TODO hartez 2018/09/12 21:43:54 The "List" part of all these cell names needs to go - internal sealed class DefaultHorizontalListCell : DefaultCell + internal sealed class HorizontalDefaultCell : DefaultCell { - public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.DefaultHorizontalListCell"); + public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.HorizontalDefaultCell"); [Export("initWithFrame:")] - public DefaultHorizontalListCell(CGRect frame) : base(frame) + public HorizontalDefaultCell(CGRect frame) : base(frame) { Constraint = Label.HeightAnchor.ConstraintEqualTo(Frame.Height); Constraint.Active = true; diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/TemplatedHorizontalListCell.cs b/Xamarin.Forms.Platform.iOS/CollectionView/HorizontalTemplatedCell.cs similarity index 80% rename from Xamarin.Forms.Platform.iOS/CollectionView/TemplatedHorizontalListCell.cs rename to Xamarin.Forms.Platform.iOS/CollectionView/HorizontalTemplatedCell.cs index 27a66370c8f..c47ac9d3723 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/TemplatedHorizontalListCell.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/HorizontalTemplatedCell.cs @@ -5,12 +5,12 @@ namespace Xamarin.Forms.Platform.iOS { - internal sealed class TemplatedHorizontalListCell : TemplatedCell + internal sealed class HorizontalTemplatedCell : TemplatedCell { - public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.TemplatedHorizontalListCell"); + public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.HorizontalTemplatedCell"); [Export("initWithFrame:")] - public TemplatedHorizontalListCell(CGRect frame) : base(frame) + public HorizontalTemplatedCell(CGRect frame) : base(frame) { } diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/DefaultVerticalListCell.cs b/Xamarin.Forms.Platform.iOS/CollectionView/VerticalDefaultCell.cs similarity index 75% rename from Xamarin.Forms.Platform.iOS/CollectionView/DefaultVerticalListCell.cs rename to Xamarin.Forms.Platform.iOS/CollectionView/VerticalDefaultCell.cs index aff7b71cd71..ea96e5c7055 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/DefaultVerticalListCell.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/VerticalDefaultCell.cs @@ -3,12 +3,12 @@ namespace Xamarin.Forms.Platform.iOS { - internal sealed class DefaultVerticalListCell : DefaultCell + internal sealed class VerticalDefaultCell : DefaultCell { - public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.DefaultVerticalListCell"); + public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.VerticalDefaultCell"); [Export("initWithFrame:")] - public DefaultVerticalListCell(CGRect frame) : base(frame) + public VerticalDefaultCell(CGRect frame) : base(frame) { Constraint = Label.WidthAnchor.ConstraintEqualTo(Frame.Width); Constraint.Active = true; diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/TemplatedVerticalListCell.cs b/Xamarin.Forms.Platform.iOS/CollectionView/VerticalTemplatedCell.cs similarity index 81% rename from Xamarin.Forms.Platform.iOS/CollectionView/TemplatedVerticalListCell.cs rename to Xamarin.Forms.Platform.iOS/CollectionView/VerticalTemplatedCell.cs index 876491a0522..3252bb3fb21 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/TemplatedVerticalListCell.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/VerticalTemplatedCell.cs @@ -6,12 +6,12 @@ namespace Xamarin.Forms.Platform.iOS { - internal sealed class TemplatedVerticalListCell : TemplatedCell + internal sealed class VerticalTemplatedCell : TemplatedCell { - public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.TemplatedVerticalListCell"); + public static NSString ReuseId = new NSString("Xamarin.Forms.Platform.iOS.VerticalTemplatedCell"); [Export("initWithFrame:")] - public TemplatedVerticalListCell(CGRect frame) : base(frame) + public VerticalTemplatedCell(CGRect frame) : base(frame) { } diff --git a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj index 8b1370cf06f..129cbbfa9e6 100644 --- a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj +++ b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj @@ -123,8 +123,8 @@ - - + + @@ -132,8 +132,8 @@ - - + +