Skip to content

Commit

Permalink
Remove extra properties from CarouselView API (xamarin#7456)
Browse files Browse the repository at this point in the history
* Remove Header/Footer properties from CarouselView

* Limit CarouselView to LinearItemsLayout

* Rework inheritance for UWP

* Split files by class

* Fix up Tizen renderer
  • Loading branch information
hartez authored and rmarinho committed Sep 13, 2019
1 parent 24fec62 commit a68dd21
Show file tree
Hide file tree
Showing 53 changed files with 775 additions and 547 deletions.
Expand Up @@ -53,7 +53,7 @@ public Issue4992 ()
};

CV.BindingContext = this;
CV.ItemsLayout = new ListItemsLayout(ItemsLayoutOrientation.Vertical); // Vertical is default
CV.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical); // Vertical is default
#endif
}

Expand Down
Expand Up @@ -62,9 +62,9 @@ internal List<CarouselData> GetCarouselItems()
return items;
}

internal ListItemsLayout GetCarouselLayout(ItemsLayoutOrientation orientation)
internal LinearItemsLayout GetCarouselLayout(ItemsLayoutOrientation orientation)
{
return new ListItemsLayout(orientation)
return new LinearItemsLayout(orientation)
{
SnapPointsType = SnapPointsType.MandatorySingle,
SnapPointsAlignment = SnapPointsAlignment.Center
Expand Down
Expand Up @@ -20,7 +20,7 @@ protected override void InitializeElement(CollectionView element)

element.HeightRequest = 250;

element.ItemsLayout = ListItemsLayout.Vertical;
element.ItemsLayout = LinearItemsLayout.Vertical;
}
}
}
Expand Up @@ -34,7 +34,7 @@ public CarouselCodeGallery(ItemsLayoutOrientation orientation)
}
};
var itemsLayout =
new ListItemsLayout(orientation)
new LinearItemsLayout(orientation)
{
SnapPointsType = SnapPointsType.MandatorySingle,
SnapPointsAlignment = SnapPointsAlignment.Center
Expand Down Expand Up @@ -71,7 +71,7 @@ public CarouselCodeGallery(ItemsLayoutOrientation orientation)
var positionControl = new PositionControl(carouselView, nItems);
layout.Children.Add(positionControl);

var spacingModifier = new SpacingModifier(carouselView, "Update Spacing");
var spacingModifier = new SpacingModifier(carouselView.ItemsLayout, "Update Spacing");

layout.Children.Add(spacingModifier);

Expand Down
Expand Up @@ -24,7 +24,7 @@ public CarouselItemsGallery()
};

var itemsLayout =
new ListItemsLayout(ItemsLayoutOrientation.Horizontal)
new LinearItemsLayout(ItemsLayoutOrientation.Horizontal)
{
SnapPointsType = SnapPointsType.MandatorySingle,
SnapPointsAlignment = SnapPointsAlignment.Center
Expand Down
Expand Up @@ -17,9 +17,9 @@ public DataTemplateGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("Vertical List (Code)", () =>
new TemplateCodeCollectionViewGallery(ListItemsLayout.Vertical), Navigation),
new TemplateCodeCollectionViewGallery(LinearItemsLayout.Vertical), Navigation),
GalleryBuilder.NavButton("Horizontal List (Code)", () =>
new TemplateCodeCollectionViewGallery(ListItemsLayout.Horizontal), Navigation),
new TemplateCodeCollectionViewGallery(LinearItemsLayout.Horizontal), Navigation),
GalleryBuilder.NavButton("Vertical Grid (Code)", () =>
new TemplateCodeCollectionViewGridGallery (), Navigation),
GalleryBuilder.NavButton("Horizontal Grid (Code)", () =>
Expand Down
Expand Up @@ -22,9 +22,9 @@ public DefaultTextGallery()
// so we can demonstrate switching between them
descriptionLabel,
GalleryBuilder.NavButton("Vertical List (Code)", () =>
new TextCodeCollectionViewGallery(ListItemsLayout.Vertical), Navigation),
new TextCodeCollectionViewGallery(LinearItemsLayout.Vertical), Navigation),
GalleryBuilder.NavButton("Horizontal List (Code)", () =>
new TextCodeCollectionViewGallery(ListItemsLayout.Horizontal), Navigation),
new TextCodeCollectionViewGallery(LinearItemsLayout.Horizontal), Navigation),
GalleryBuilder.NavButton("Vertical Grid (Code)", () =>
new TextCodeCollectionViewGridGallery(), Navigation),
GalleryBuilder.NavButton("Horizontal Grid (Code)", () =>
Expand Down
Expand Up @@ -17,9 +17,9 @@ public ItemsSizeGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("Expanding Text (Vertical List)", () =>
new DynamicItemSizeGallery(ListItemsLayout.Vertical), Navigation),
new DynamicItemSizeGallery(LinearItemsLayout.Vertical), Navigation),
GalleryBuilder.NavButton("Expanding Text (Horizontal List)", () =>
new DynamicItemSizeGallery(ListItemsLayout.Horizontal), Navigation),
new DynamicItemSizeGallery(LinearItemsLayout.Horizontal), Navigation),
GalleryBuilder.NavButton("ItemSizing Strategy", () =>
new VariableSizeTemplateGridGallery (ItemsLayoutOrientation.Horizontal), Navigation)
}
Expand Down
Expand Up @@ -21,7 +21,7 @@ internal class ObservableCodeCollectionViewGallery : ContentPage

IItemsLayout itemsLayout = grid
? new GridItemsLayout(3, orientation)
: new ListItemsLayout(orientation) as IItemsLayout;
: new LinearItemsLayout(orientation) as IItemsLayout;

var itemTemplate = ExampleTemplates.PhotoTemplate();

Expand Down
Expand Up @@ -20,7 +20,7 @@ internal class ObservableMultiItemCollectionViewGallery : ContentPage

var itemsLayout = grid
? new GridItemsLayout(3, orientation)
: new ListItemsLayout(orientation) as IItemsLayout;
: new LinearItemsLayout(orientation) as IItemsLayout;

var itemTemplate = ExampleTemplates.PhotoTemplate();

Expand Down
Expand Up @@ -17,10 +17,10 @@ public PropagationGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("Propagate FlowDirection", () =>
new PropagateCodeGallery(ListItemsLayout.Vertical), Navigation),
new PropagateCodeGallery(LinearItemsLayout.Vertical), Navigation),

GalleryBuilder.NavButton("Propagate FlowDirection in EmptyView", () =>
new PropagateCodeGallery(ListItemsLayout.Vertical, 0), Navigation),
new PropagateCodeGallery(LinearItemsLayout.Vertical, 0), Navigation),
}
}
};
Expand Down
Expand Up @@ -20,7 +20,7 @@ public ScrollModeTestGallery(IItemsLayout itemsLayout = null, Func<DataTemplate>
InitializeComponent();

_collectionView = createCollectionView == null ? new CollectionView() : createCollectionView();
_collectionView.ItemsLayout = itemsLayout ?? ListItemsLayout.Vertical;
_collectionView.ItemsLayout = itemsLayout ?? LinearItemsLayout.Vertical;

var scrollModeSelector = new EnumSelector<ItemsUpdatingScrollMode>(() => _collectionView.ItemsUpdatingScrollMode,
mode => _collectionView.ItemsUpdatingScrollMode = mode, "SelectScrollMode");
Expand Down
Expand Up @@ -19,9 +19,9 @@ public ScrollToGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("ScrollTo Index (Code, Horizontal List)", () =>
new ScrollToCodeGallery(ListItemsLayout.Horizontal), Navigation),
new ScrollToCodeGallery(LinearItemsLayout.Horizontal), Navigation),
GalleryBuilder.NavButton("ScrollTo Index (Code, Vertical List)", () =>
new ScrollToCodeGallery(ListItemsLayout.Vertical), Navigation),
new ScrollToCodeGallery(LinearItemsLayout.Vertical), Navigation),
GalleryBuilder.NavButton("ScrollTo Index (Code, Horizontal Grid)", () =>
new ScrollToCodeGallery(new GridItemsLayout(3, ItemsLayoutOrientation.Horizontal)),
Navigation),
Expand All @@ -30,10 +30,10 @@ public ScrollToGallery()
Navigation),

GalleryBuilder.NavButton("ScrollTo Item (Code, Horizontal List)", () =>
new ScrollToCodeGallery(ListItemsLayout.Horizontal, ScrollToMode.Element,
new ScrollToCodeGallery(LinearItemsLayout.Horizontal, ScrollToMode.Element,
ExampleTemplates.ScrollToItemTemplate), Navigation),
GalleryBuilder.NavButton("ScrollTo Item (Code, Vertical List)", () =>
new ScrollToCodeGallery(ListItemsLayout.Vertical, ScrollToMode.Element,
new ScrollToCodeGallery(LinearItemsLayout.Vertical, ScrollToMode.Element,
ExampleTemplates.ScrollToItemTemplate), Navigation),
GalleryBuilder.NavButton("ScrollTo Item (Code, Horizontal Grid)", () =>
new ScrollToCodeGallery(new GridItemsLayout(3, ItemsLayoutOrientation.Horizontal),
Expand Down
Expand Up @@ -19,9 +19,9 @@ public SnapPointsGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("Snap Points (Code, Horizontal List)", () =>
new SnapPointsCodeGallery(ListItemsLayout.Horizontal as ItemsLayout), Navigation),
new SnapPointsCodeGallery(LinearItemsLayout.Horizontal as ItemsLayout), Navigation),
GalleryBuilder.NavButton("Snap Points (Code, Vertical List)", () =>
new SnapPointsCodeGallery(ListItemsLayout.Vertical as ItemsLayout), Navigation),
new SnapPointsCodeGallery(LinearItemsLayout.Vertical as ItemsLayout), Navigation),
GalleryBuilder.NavButton("Snap Points (Code, Horizontal Grid)", () =>
new SnapPointsCodeGallery(new GridItemsLayout(2, ItemsLayoutOrientation.Horizontal)), Navigation),
GalleryBuilder.NavButton("Snap Points (Code, Vertical Grid)", () =>
Expand Down
Expand Up @@ -17,9 +17,9 @@ public ItemsSpacingGallery()
{
descriptionLabel,
GalleryBuilder.NavButton("Vertical List Spacing", () =>
new SpacingGallery (ListItemsLayout.Vertical), Navigation),
new SpacingGallery (LinearItemsLayout.Vertical), Navigation),
GalleryBuilder.NavButton("Horizontal List Spacing", () =>
new SpacingGallery (ListItemsLayout.Horizontal), Navigation),
new SpacingGallery (LinearItemsLayout.Horizontal), Navigation),
GalleryBuilder.NavButton("Vertical Grid Spacing", () =>
new SpacingGallery (new GridItemsLayout(3, ItemsLayoutOrientation.Vertical)), Navigation),
GalleryBuilder.NavButton("Horizontal Grid Spacing", () =>
Expand Down
Expand Up @@ -36,7 +36,7 @@ public SpacingGallery(IItemsLayout itemsLayout)
};

var generator = new ItemsSourceGenerator(collectionView, initialItems: 20);
var spacingModifier = new SpacingModifier(collectionView, "Update Spacing");
var spacingModifier = new SpacingModifier(collectionView.ItemsLayout, "Update Spacing");

layout.Children.Add(generator);
layout.Children.Add(instructions);
Expand Down
Expand Up @@ -4,12 +4,12 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.SpacingGal
{
internal class SpacingModifier : ContentView
{
protected readonly ItemsView _cv;
protected readonly Entry Entry;
protected readonly IItemsLayout ItemsLayout;

public SpacingModifier(ItemsView cv, string buttonText)
public SpacingModifier(IItemsLayout itemsLayout, string buttonText)
{
_cv = cv;
ItemsLayout = itemsLayout;

var layout = new StackLayout
{
Expand Down Expand Up @@ -38,7 +38,7 @@ void ButtonOnClicked(object sender, EventArgs e)

protected virtual string LabelText => "Spacing:";

protected virtual string InitialEntryText => _cv.ItemsLayout is GridItemsLayout ? "0, 0" : "0";
protected virtual string InitialEntryText => ItemsLayout is GridItemsLayout ? "0, 0" : "0";

protected virtual void OnButtonClicked()
{
Expand All @@ -47,11 +47,11 @@ protected virtual void OnButtonClicked()
return;
}

if (_cv.ItemsLayout is ListItemsLayout listItemsLayout)
if (ItemsLayout is LinearItemsLayout listItemsLayout)
{
listItemsLayout.ItemSpacing = indexes[0];
}
else if (_cv.ItemsLayout is GridItemsLayout gridItemsLayout)
else if (ItemsLayout is GridItemsLayout gridItemsLayout)
{
gridItemsLayout.VerticalItemSpacing = indexes[0];
gridItemsLayout.HorizontalItemSpacing = indexes[1];
Expand All @@ -60,7 +60,7 @@ protected virtual void OnButtonClicked()

protected virtual bool ParseIndexes(out int[] indexes)
{
if (_cv.ItemsLayout is ListItemsLayout listItemsLayout)
if (ItemsLayout is LinearItemsLayout listItemsLayout)
{
return IndexParser.ParseIndexes(Entry.Text, 1, out indexes);
}
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Forms.Core.UnitTests/ItemsViewTests.cs
Expand Up @@ -26,7 +26,7 @@ public override void TearDown()
[Test]
public void VerticalListMeasurement()
{
var itemsView = new ItemsView();
var itemsView = new StructuredItemsView();

var sizeRequest = itemsView.Measure(double.PositiveInfinity, double.PositiveInfinity);

Expand All @@ -37,9 +37,9 @@ public void VerticalListMeasurement()
[Test]
public void HorizontalListMeasurement()
{
var itemsView = new ItemsView();
var itemsView = new StructuredItemsView();

itemsView.ItemsLayout = new ListItemsLayout(ItemsLayoutOrientation.Horizontal);
itemsView.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);

var sizeRequest = itemsView.Measure(double.PositiveInfinity, double.PositiveInfinity);

Expand Down
12 changes: 11 additions & 1 deletion Xamarin.Forms.Core/Items/CarouselView.cs
Expand Up @@ -154,13 +154,23 @@ public object PositionChangedCommandParameter
set => SetValue(PositionChangedCommandParameterProperty, value);
}

public static readonly BindableProperty ItemsLayoutProperty =
BindableProperty.Create(nameof(ItemsLayout), typeof(LinearItemsLayout), typeof(ItemsView),
LinearItemsLayout.Horizontal);

public LinearItemsLayout ItemsLayout
{
get => (LinearItemsLayout)InternalItemsLayout;
set => InternalItemsLayout = value;
}

public event EventHandler<CurrentItemChangedEventArgs> CurrentItemChanged;
public event EventHandler<PositionChangedEventArgs> PositionChanged;

public CarouselView()
{
CollectionView.VerifyCollectionViewFlagEnabled(constructorHint: nameof(CarouselView));
ItemsLayout = new ListItemsLayout(ItemsLayoutOrientation.Horizontal)
ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal)
{
SnapPointsType = SnapPointsType.MandatorySingle,
SnapPointsAlignment = SnapPointsAlignment.Center
Expand Down
4 changes: 2 additions & 2 deletions Xamarin.Forms.Core/Items/ItemsLayoutTypeConverter.cs
Expand Up @@ -9,12 +9,12 @@ public override object ConvertFromInvariantString(string value)
{
if (value == "HorizontalList")
{
return ListItemsLayout.Horizontal;
return LinearItemsLayout.Horizontal;
}

if (value == "VerticalList")
{
return ListItemsLayout.Vertical;
return LinearItemsLayout.Vertical;
}

throw new InvalidOperationException($"Cannot convert \"{value}\" into {typeof(IItemsLayout)}");
Expand Down

0 comments on commit a68dd21

Please sign in to comment.