[Core,iOS,Android] Remove NumberOfSideItems (#8614)

* [Core,iOS,Android] Remove number of side items

* [Controls] Fix IndicadorCodeGallery
This commit is contained in:
Rui Marinho 2019-11-27 17:52:46 +00:00 коммит произвёл GitHub
Родитель 1c61f2f61c
Коммит 67f7eda2cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 11 добавлений и 55 удалений

Просмотреть файл

@ -28,16 +28,12 @@ namespace Xamarin.Forms.Controls
var currentItemContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.CurrentItem, new CarouselView { HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate(), CurrentItem = _currentItem }, "CurrentItem", value => value.ToString());
var isSwipeEnabledContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.IsSwipeEnabled, new CarouselView { IsSwipeEnabled = false, HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate()}, "IsSwipeEnabled", value => value.ToString());
var isScrollAnimatedContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.IsScrollAnimated, new CarouselView { IsScrollAnimated = false, HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate() }, "IsScrollAnimated", value => value.ToString());
var horizontalNumberOfSideItemsContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.NumberOfSideItems, new CarouselView { NumberOfSideItems = 2, HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate() }, "NumberOfSideItems", value => value.ToString());
var verticalNumberOfSideItemsContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.NumberOfSideItems, new CarouselView { NumberOfSideItems = 2, HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Vertical), ItemTemplate = GetCarouselTemplate() }, "NumberOfSideItems", value => value.ToString());
var peekAreaInsetsContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.PeekAreaInsets, new CarouselView { PeekAreaInsets = new Thickness(24, 12, 36, 6), HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate() }, "PeekAreaInsets", value => value.ToString());
var positionContainer = new ValueViewContainer<CarouselView>(Test.CarouselView.Position, new CarouselView { Position = 2, HeightRequest = 250, ItemsSource = GetCarouselItems(), ItemsLayout = GetCarouselLayout(ItemsLayoutOrientation.Horizontal), ItemTemplate = GetCarouselTemplate() }, "Position", value => value.ToString());
Add(currentItemContainer);
Add(isSwipeEnabledContainer);
Add(isScrollAnimatedContainer);
Add(horizontalNumberOfSideItemsContainer);
Add(verticalNumberOfSideItemsContainer);
Add(peekAreaInsetsContainer);
Add(positionContainer);
}

Просмотреть файл

@ -47,7 +47,7 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.CarouselVi
layout.Children.Add(carouselView);
var generator = new ItemsSourceGenerator(carouselView, nItems, ItemsSourceType.ObservableCollection, false);
var generator = new ItemsSourceGenerator(carouselView, nItems, ItemsSourceType.ObservableCollection);
layout.Children.Add(generator);

Просмотреть файл

@ -20,14 +20,13 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries
readonly ItemsView _cv;
private readonly ItemsSourceType _itemsSourceType;
readonly Entry _entry;
readonly Entry _entrySideItems;
int _count = 0;
CarouselView carousel => _cv as CarouselView;
public int Count => _count;
public ItemsSourceGenerator(ItemsView cv, int initialItems = 1000,
ItemsSourceType itemsSourceType = ItemsSourceType.List, bool sideItems = true)
ItemsSourceType itemsSourceType = ItemsSourceType.List)
{
_count = initialItems;
_cv = cv;
@ -42,18 +41,10 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries
var label = new Label { Text = "Items:", VerticalTextAlignment = TextAlignment.Center };
_entry = new Entry { Keyboard = Keyboard.Numeric, Text = initialItems.ToString(), WidthRequest = 100, AutomationId = "entryUpdate" };
layout.Children.Add(label);
layout.Children.Add(_entry);
if (sideItems)
{
var labelSideItems = new Label { Text = "Side items:", VerticalTextAlignment = TextAlignment.Center };
_entrySideItems = new Entry { Keyboard = Keyboard.Numeric, Text = carousel?.NumberOfSideItems.ToString(), WidthRequest = 100, AutomationId = "entrySideItemsUpdate" };
layout.Children.Add(labelSideItems);
layout.Children.Add(_entrySideItems);
}
layout.Children.Add(button);
button.Clicked += GenerateItems;
@ -174,9 +165,6 @@ namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries
if (carousel == null)
return;
if (int.TryParse(_entrySideItems?.Text, out int count))
carousel.NumberOfSideItems = count;
}
}
}

Просмотреть файл

@ -47,15 +47,6 @@ namespace Xamarin.Forms
set { SetValue(IsBounceEnabledProperty, value); }
}
public static readonly BindableProperty NumberOfSideItemsProperty =
BindableProperty.Create(nameof(NumberOfSideItems), typeof(int), typeof(CarouselView), 0);
public int NumberOfSideItems
{
get { return (int)GetValue(NumberOfSideItemsProperty); }
set { SetValue(NumberOfSideItemsProperty, value); }
}
public static readonly BindableProperty IsSwipeEnabledProperty =
BindableProperty.Create(nameof(IsSwipeEnabled), typeof(bool), typeof(CarouselView), true);

Просмотреть файл

@ -132,8 +132,7 @@ namespace Xamarin.Forms.Platform.Android
if (ItemsLayout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
{
var numberOfVisibleItems = Carousel.NumberOfSideItems * 2 + 1;
itemWidth = (int)(Width - Carousel.PeekAreaInsets.Left - Carousel.PeekAreaInsets.Right - Context?.ToPixels(listItemsLayout.ItemSpacing)) / numberOfVisibleItems;
itemWidth = (int)(Width - Carousel.PeekAreaInsets.Left - Carousel.PeekAreaInsets.Right - Context?.ToPixels(listItemsLayout.ItemSpacing));
}
return itemWidth;
@ -145,8 +144,7 @@ namespace Xamarin.Forms.Platform.Android
if (ItemsLayout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
{
var numberOfVisibleItems = Carousel.NumberOfSideItems * 2 + 1;
itemHeight = (int)(Height - Carousel.PeekAreaInsets.Top - Carousel.PeekAreaInsets.Bottom - Context?.ToPixels(listItemsLayout.ItemSpacing)) / numberOfVisibleItems;
itemHeight = (int)(Height - Carousel.PeekAreaInsets.Top - Carousel.PeekAreaInsets.Bottom - Context?.ToPixels(listItemsLayout.ItemSpacing));
}
return itemHeight;

Просмотреть файл

@ -30,7 +30,7 @@ namespace Xamarin.Forms.Platform.UWP
{
base.OnElementPropertyChanged(sender, changedProperty);
if (changedProperty.IsOneOf(CarouselView.ItemsSourceProperty, CarouselView.NumberOfSideItemsProperty, LinearItemsLayout.ItemSpacingProperty))
if (changedProperty.IsOneOf(CarouselView.ItemsSourceProperty, LinearItemsLayout.ItemSpacingProperty))
UpdateItemsSource();
else if (changedProperty.Is(CarouselView.ItemTemplateProperty))
UpdateItemTemplate();
@ -248,8 +248,7 @@ namespace Xamarin.Forms.Platform.UWP
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
{
var numberOfVisibleItems = CarouselView.NumberOfSideItems * 2 + 1;
itemWidth = (ActualWidth - CarouselView.PeekAreaInsets.Left - CarouselView.PeekAreaInsets.Right - CarouselItemsLayout.ItemSpacing) / numberOfVisibleItems;
itemWidth = (ActualWidth - CarouselView.PeekAreaInsets.Left - CarouselView.PeekAreaInsets.Right - CarouselItemsLayout.ItemSpacing);
}
return Math.Max(itemWidth, 0);
@ -261,8 +260,7 @@ namespace Xamarin.Forms.Platform.UWP
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
{
var numberOfVisibleItems = CarouselView.NumberOfSideItems * 2 + 1;
itemHeight = (ActualHeight - CarouselView.PeekAreaInsets.Top - CarouselView.PeekAreaInsets.Bottom - CarouselItemsLayout.ItemSpacing) / numberOfVisibleItems;
itemHeight = (ActualHeight - CarouselView.PeekAreaInsets.Top - CarouselView.PeekAreaInsets.Bottom - CarouselItemsLayout.ItemSpacing);
}
return Math.Max(itemHeight, 0);

Просмотреть файл

@ -23,9 +23,8 @@ namespace Xamarin.Forms.Platform.iOS
public override void ConstrainTo(CGSize size)
{
//TODO: Should we scale the items
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;
var width = size.Width - _carouselView.PeekAreaInsets.Left - _carouselView.PeekAreaInsets.Right;
var height = size.Height - _carouselView.PeekAreaInsets.Top - _carouselView.PeekAreaInsets.Bottom;
if (ScrollDirection == UICollectionViewScrollDirection.Horizontal)
{
@ -59,20 +58,6 @@ namespace Xamarin.Forms.Platform.iOS
var top = insets.Top + (float)_carouselView.PeekAreaInsets.Top;
var bottom = insets.Bottom + (float)_carouselView.PeekAreaInsets.Bottom;
// We give some insets so the user can scroll to the first and last item
if (_carouselView.NumberOfSideItems > 0)
{
if (ScrollDirection == UICollectionViewScrollDirection.Horizontal)
{
left += ItemSize.Width;
right += ItemSize.Width;
return new UIEdgeInsets(insets.Top, left, insets.Bottom, right);
}
return new UIEdgeInsets(ItemSize.Height, insets.Left, ItemSize.Height, insets.Right);
}
return new UIEdgeInsets(top, left, bottom, right);
}
}

Просмотреть файл

@ -20,7 +20,7 @@ namespace Xamarin.Forms.Platform.iOS
{
base.OnElementPropertyChanged(sender, changedProperty);
if (changedProperty.IsOneOf(CarouselView.PeekAreaInsetsProperty, CarouselView.NumberOfSideItemsProperty))
if (changedProperty.Is(CarouselView.PeekAreaInsetsProperty))
{
(Controller.Layout as CarouselViewLayout).UpdateConstraints(Frame.Size);
Controller.Layout.InvalidateLayout();