From: E.Z. Hart Date: Thu, 21 Nov 2019 15:53:39 +0000 (-0700) Subject: Remove ItemSizingStrategy from CarouselView (#8588) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~77^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ce747e5eadfaf5c50ed4fe62cb8e5db9dc3ff3c;p=platform%2Fcore%2Fcsapi%2Fxsf.git Remove ItemSizingStrategy from CarouselView (#8588) * Move ItemSizingStrategy * Fix tests * Fix Android * Fix Tizen * Fix iOS --- diff --git a/Xamarin.Forms.Core.UnitTests/CarouselViewTests.cs b/Xamarin.Forms.Core.UnitTests/CarouselViewTests.cs index 417dfab..e42ca5e 100644 --- a/Xamarin.Forms.Core.UnitTests/CarouselViewTests.cs +++ b/Xamarin.Forms.Core.UnitTests/CarouselViewTests.cs @@ -33,7 +33,6 @@ namespace Xamarin.Forms.Core.UnitTests Assert.IsNull(carouselView.ItemTemplate); Assert.IsNotNull(carouselView.ItemsLayout); Assert.IsTrue(carouselView.Position == 0); - Assert.IsTrue(carouselView.ItemSizingStrategy == ItemSizingStrategy.None); } [Test] diff --git a/Xamarin.Forms.Core/Items/CarouselView.cs b/Xamarin.Forms.Core/Items/CarouselView.cs index 6b23e0a..d68c652 100644 --- a/Xamarin.Forms.Core/Items/CarouselView.cs +++ b/Xamarin.Forms.Core/Items/CarouselView.cs @@ -180,7 +180,6 @@ namespace Xamarin.Forms SnapPointsType = SnapPointsType.MandatorySingle, SnapPointsAlignment = SnapPointsAlignment.Center }; - ItemSizingStrategy = ItemSizingStrategy.None; } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/Xamarin.Forms.Core/Items/ItemSizingStrategy.cs b/Xamarin.Forms.Core/Items/ItemSizingStrategy.cs index e237689..c7cb166 100644 --- a/Xamarin.Forms.Core/Items/ItemSizingStrategy.cs +++ b/Xamarin.Forms.Core/Items/ItemSizingStrategy.cs @@ -3,7 +3,6 @@ public enum ItemSizingStrategy { MeasureAllItems, - MeasureFirstItem, - None + MeasureFirstItem } } \ No newline at end of file diff --git a/Xamarin.Forms.Core/Items/ItemsView.cs b/Xamarin.Forms.Core/Items/ItemsView.cs index 37f25ff..a5824c3 100644 --- a/Xamarin.Forms.Core/Items/ItemsView.cs +++ b/Xamarin.Forms.Core/Items/ItemsView.cs @@ -131,15 +131,6 @@ namespace Xamarin.Forms set => SetValue(InternalItemsLayoutProperty, value); } - public static readonly BindableProperty ItemSizingStrategyProperty = - BindableProperty.Create(nameof(ItemSizingStrategy), typeof(ItemSizingStrategy), typeof(ItemsView)); - - public ItemSizingStrategy ItemSizingStrategy - { - get => (ItemSizingStrategy)GetValue(ItemSizingStrategyProperty); - set => SetValue(ItemSizingStrategyProperty, value); - } - public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(ItemsView)); diff --git a/Xamarin.Forms.Core/Items/StructuredItemsView.cs b/Xamarin.Forms.Core/Items/StructuredItemsView.cs index 4b09ff0..9e9b77c 100644 --- a/Xamarin.Forms.Core/Items/StructuredItemsView.cs +++ b/Xamarin.Forms.Core/Items/StructuredItemsView.cs @@ -45,5 +45,14 @@ get => InternalItemsLayout; set => InternalItemsLayout = value; } + + public static readonly BindableProperty ItemSizingStrategyProperty = + BindableProperty.Create(nameof(ItemSizingStrategy), typeof(ItemSizingStrategy), typeof(ItemsView)); + + public ItemSizingStrategy ItemSizingStrategy + { + get => (ItemSizingStrategy)GetValue(ItemSizingStrategyProperty); + set => SetValue(ItemSizingStrategyProperty, value); + } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs index 3879519..171a019 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/CarouselViewRenderer.cs @@ -167,7 +167,7 @@ namespace Xamarin.Forms.Platform.Android UpdateAdapter(); } - void UpdateAdapter() + protected override void UpdateAdapter() { // By default the CollectionViewAdapter creates the items at whatever size the template calls for // But for the Carousel, we want it to create the items to fit the width/height of the viewport diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs index 400da14..d323e70 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewAdapter.cs @@ -16,8 +16,6 @@ namespace Xamarin.Forms.Platform.Android internal TItemsViewSource ItemsSource; bool _disposed; - Size? _size; - bool _usingItemTemplate = false; internal ItemsViewAdapter(TItemsView itemsView, Func createItemContentView = null) @@ -126,16 +124,9 @@ namespace Xamarin.Forms.Platform.Android return ItemsSource.GetPosition(item); } - protected void BindTemplatedItemViewHolder(TemplatedItemViewHolder templatedItemViewHolder, object context) + protected virtual void BindTemplatedItemViewHolder(TemplatedItemViewHolder templatedItemViewHolder, object context) { - if (ItemsView.ItemSizingStrategy == ItemSizingStrategy.MeasureFirstItem) - { - templatedItemViewHolder.Bind(context, ItemsView, SetStaticSize, _size); - } - else - { - templatedItemViewHolder.Bind(context, ItemsView); - } + templatedItemViewHolder.Bind(context, ItemsView); } void UpdateItemsSource() @@ -145,11 +136,6 @@ namespace Xamarin.Forms.Platform.Android ItemsSource = CreateItemsSource(); } - void SetStaticSize(Size size) - { - _size = size; - } - void UpdateUsingItemTemplate() { _usingItemTemplate = ItemsView.ItemTemplate != null; diff --git a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs index 89a432b..d1f086d 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs @@ -228,10 +228,6 @@ namespace Xamarin.Forms.Platform.Android { UpdateEmptyView(); } - else if (changedProperty.Is(Xamarin.Forms.ItemsView.ItemSizingStrategyProperty)) - { - UpdateAdapter(); - } else if (changedProperty.Is(Xamarin.Forms.ItemsView.HorizontalScrollBarVisibilityProperty)) { UpdateHorizontalScrollBarVisibility(); @@ -272,7 +268,7 @@ namespace Xamarin.Forms.Platform.Android return (TAdapter)new ItemsViewAdapter(ItemsView); } - void UpdateAdapter() + protected virtual void UpdateAdapter() { var oldItemViewAdapter = ItemsViewAdapter; diff --git a/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewAdapter.cs b/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewAdapter.cs index 7239c5c..b274ba1 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewAdapter.cs @@ -10,6 +10,8 @@ namespace Xamarin.Forms.Platform.Android where TItemsView : StructuredItemsView where TItemsViewSource : IItemsViewSource { + Size? _size; + internal StructuredItemsViewAdapter(TItemsView itemsView, Func createItemContentView = null) : base(itemsView, createItemContentView) { @@ -90,6 +92,18 @@ namespace Xamarin.Forms.Platform.Android base.OnBindViewHolder(holder, position); } + protected override void BindTemplatedItemViewHolder(TemplatedItemViewHolder templatedItemViewHolder, object context) + { + if (ItemsView.ItemSizingStrategy == ItemSizingStrategy.MeasureFirstItem) + { + templatedItemViewHolder.Bind(context, ItemsView, SetStaticSize, _size); + } + else + { + base.BindTemplatedItemViewHolder(templatedItemViewHolder, context); + } + } + void UpdateHasHeader() { ItemsSource.HasHeader = ItemsView.Header != null; @@ -126,5 +140,10 @@ namespace Xamarin.Forms.Platform.Android // No template, Footer is not a Forms View, so just display Footer.ToString return SimpleViewHolder.FromText(content?.ToString(), context, fill: false); } + + void SetStaticSize(Size size) + { + _size = size; + } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewRenderer.cs b/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewRenderer.cs index bdfdae0..e8dcf1c 100644 --- a/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/CollectionView/StructuredItemsViewRenderer.cs @@ -22,6 +22,10 @@ namespace Xamarin.Forms.Platform.Android { UpdateLayoutManager(); } + else if (changedProperty.Is(StructuredItemsView.ItemSizingStrategyProperty)) + { + UpdateAdapter(); + } } protected override TAdapter CreateAdapter() diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/ItemsViewRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/ItemsViewRenderer.cs index 5aab9dd..f23c7ef 100644 --- a/Xamarin.Forms.Platform.Tizen/Renderers/ItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.Tizen/Renderers/ItemsViewRenderer.cs @@ -14,7 +14,7 @@ namespace Xamarin.Forms.Platform.Tizen RegisterPropertyHandler(ItemsView.ItemsSourceProperty, UpdateItemsSource); RegisterPropertyHandler(ItemsView.ItemTemplateProperty, UpdateAdaptor); RegisterPropertyHandler(StructuredItemsView.ItemsLayoutProperty, UpdateItemsLayout); - RegisterPropertyHandler(ItemsView.ItemSizingStrategyProperty, UpdateSizingStrategy); + RegisterPropertyHandler(StructuredItemsView.ItemSizingStrategyProperty, UpdateSizingStrategy); RegisterPropertyHandler(SelectableItemsView.SelectedItemProperty, UpdateSelectedItem); RegisterPropertyHandler(SelectableItemsView.SelectionModeProperty, UpdateSelectionMode); } diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewLayout.cs b/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewLayout.cs index 905e1fc..751e1a6 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewLayout.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewLayout.cs @@ -9,7 +9,7 @@ namespace Xamarin.Forms.Platform.iOS readonly CarouselView _carouselView; readonly ItemsLayout _itemsLayout; - public CarouselViewLayout(ItemsLayout itemsLayout, ItemSizingStrategy itemSizingStrategy, CarouselView carouselView) : base(itemsLayout, itemSizingStrategy) + public CarouselViewLayout(ItemsLayout itemsLayout, CarouselView carouselView) : base(itemsLayout) { _carouselView = carouselView; _itemsLayout = itemsLayout; @@ -23,7 +23,6 @@ namespace Xamarin.Forms.Platform.iOS public override void ConstrainTo(CGSize size) { //TODO: Should we scale the items - var aspectRatio = size.Width / size.Height; var numberOfVisibleItems = _carouselView.NumberOfSideItems * 2 + 1; var width = (size.Width - _carouselView.PeekAreaInsets.Left - _carouselView.PeekAreaInsets.Right) / numberOfVisibleItems; var height = (size.Height - _carouselView.PeekAreaInsets.Top - _carouselView.PeekAreaInsets.Bottom) / numberOfVisibleItems; diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewRenderer.cs index eb26796..62aafb9 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/CarouselViewRenderer.cs @@ -33,7 +33,7 @@ namespace Xamarin.Forms.Platform.iOS protected override ItemsViewLayout SelectLayout() { - return new CarouselViewLayout(CarouselView.ItemsLayout, CarouselView.ItemSizingStrategy, CarouselView); + return new CarouselViewLayout(CarouselView.ItemsLayout, CarouselView); } protected override void SetUpNewElement(CarouselView newElement) diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs index 728bbee..ef5fb0a 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewLayout.cs @@ -18,7 +18,13 @@ namespace Xamarin.Forms.Platform.iOS public ItemsUpdatingScrollMode ItemsUpdatingScrollMode { get; set; } - protected ItemsViewLayout(ItemsLayout itemsLayout, ItemSizingStrategy itemSizingStrategy) + public nfloat ConstrainedDimension { get; set; } + + public Func GetPrototype { get; set; } + + internal ItemSizingStrategy ItemSizingStrategy { get; private set; } + + protected ItemsViewLayout(ItemsLayout itemsLayout, ItemSizingStrategy itemSizingStrategy = ItemSizingStrategy.MeasureFirstItem) { ItemSizingStrategy = itemSizingStrategy; @@ -75,12 +81,6 @@ namespace Xamarin.Forms.Platform.iOS } } - public nfloat ConstrainedDimension { get; set; } - - public Func GetPrototype { get; set; } - - internal ItemSizingStrategy ItemSizingStrategy { get; private set; } - public abstract void ConstrainTo(CGSize size); public virtual UIEdgeInsets GetInsetForSection(UICollectionView collectionView, UICollectionViewLayout layout, diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs index 522bf43..a4b5427 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs @@ -15,8 +15,6 @@ namespace Xamarin.Forms.Platform.iOS protected TItemsView ItemsView => Element; - - public override UIViewController ViewController => Controller; protected TViewController Controller { get; private set; } @@ -56,10 +54,6 @@ namespace Xamarin.Forms.Platform.iOS { Controller.UpdateEmptyView(); } - else if (changedProperty.Is(Xamarin.Forms.ItemsView.ItemSizingStrategyProperty)) - { - UpdateItemSizingStrategy(); - } else if (changedProperty.Is(Xamarin.Forms.ItemsView.HorizontalScrollBarVisibilityProperty)) { UpdateHorizontalScrollBarVisibility(); diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/StructuredItemsViewRenderer.cs b/Xamarin.Forms.Platform.iOS/CollectionView/StructuredItemsViewRenderer.cs index 8dcb855..f6f761f 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/StructuredItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/StructuredItemsViewRenderer.cs @@ -27,6 +27,10 @@ namespace Xamarin.Forms.Platform.iOS { UpdateLayout(); } + else if (changedProperty.Is(StructuredItemsView.ItemSizingStrategyProperty)) + { + UpdateItemSizingStrategy(); + } } protected override void SetUpNewElement(TItemsView newElement)