Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Merge branch '4.3.0' into fix-gh7700
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez authored Oct 13, 2019
2 parents b579cd1 + 333d3a0 commit a47a6e3
Show file tree
Hide file tree
Showing 24 changed files with 443 additions and 426 deletions.
14 changes: 8 additions & 6 deletions Stubs/Xamarin.Forms.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,26 @@ internal class _ImageRenderer { }
[RenderWith (typeof (ButtonRenderer))]
internal class _ButtonRenderer { }

#if __ANDROID__
[RenderWith(typeof(ImageButtonRenderer))]
#elif !TIZEN4_0
[RenderWith(typeof(ImageButtonRenderer))]
#endif
internal class _ImageButtonRenderer { }

[RenderWith (typeof (TableViewRenderer))]
internal class _TableViewRenderer { }

[RenderWith (typeof (ListViewRenderer))]
internal class _ListViewRenderer { }
#if !TIZEN4_0
#if !TIZEN4_0
[RenderWith (typeof (CollectionViewRenderer))]
#else
[RenderWith (typeof (ItemsViewRenderer))]
#endif
internal class _CollectionViewRenderer { }

#if !TIZEN4_0
[RenderWith (typeof (CarouselViewRenderer))]
internal class _CarouselViewRenderer { }
#endif
internal class _CarouselViewRenderer { }

[RenderWith (typeof (SliderRenderer))]
internal class _SliderRenderer { }

Expand Down
90 changes: 34 additions & 56 deletions Xamarin.Forms.Platform.UAP/CollectionView/CarouselViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

namespace Xamarin.Forms.Platform.UWP
{
public class CarouselViewRenderer : ItemsViewRenderer
public class CarouselViewRenderer : ItemsViewRenderer<CarouselView>
{
ScrollViewer _scrollViewer;
public CarouselViewRenderer()
{
CollectionView.VerifyCollectionViewFlagEnabled(nameof(CarouselView));
}

CarouselView CarouselView => (CarouselView)Element;
CarouselView CarouselView => Element;
protected override IItemsLayout Layout => CarouselView?.ItemsLayout;
LinearItemsLayout CarouselItemsLayout => CarouselView?.ItemsLayout;

UWPDataTemplate CarouselItemsViewTemplate => (UWPDataTemplate)UWPApp.Current.Resources["CarouselItemsViewDefaultTemplate"];

double _itemWidth;
Expand All @@ -30,9 +32,9 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
{
base.OnElementPropertyChanged(sender, changedProperty);

if (changedProperty.IsOneOf(ItemsView.ItemsSourceProperty, CarouselView.NumberOfSideItemsProperty, LinearItemsLayout.ItemSpacingProperty))
if (changedProperty.IsOneOf(CarouselView.ItemsSourceProperty, CarouselView.NumberOfSideItemsProperty, LinearItemsLayout.ItemSpacingProperty))
UpdateItemsSource();
else if (changedProperty.Is(ItemsView.ItemTemplateProperty))
else if (changedProperty.Is(CarouselView.ItemTemplateProperty))
UpdateItemTemplate();
else if (changedProperty.Is(CarouselView.PeekAreaInsetsProperty))
UpdatePeekAreaInsets();
Expand All @@ -42,9 +44,9 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateIsBounceEnabled();
}

protected override void HandleLayoutPropertyChange(PropertyChangedEventArgs property)
protected override void HandleLayoutPropertyChanged(PropertyChangedEventArgs property)
{
if (property.IsOneOf(LinearItemsLayout.ItemSpacingProperty, GridItemsLayout.HorizontalItemSpacingProperty, GridItemsLayout.VerticalItemSpacingProperty))
if (property.IsOneOf(LinearItemsLayout.ItemSpacingProperty))
UpdateItemSpacing();
else if (property.Is(ItemsLayout.SnapPointsTypeProperty))
UpdateSnapPointsType();
Expand Down Expand Up @@ -108,19 +110,7 @@ protected override CollectionViewSource CreateCollectionViewSource()

protected override ListViewBase SelectListViewBase()
{
ListViewBase listView = null;

switch (Layout)
{
case LinearItemsLayout listItemsLayout:
listView = CreateCarouselListLayout(listItemsLayout.Orientation);
break;
}

if (listView == null)
{
listView = new FormsListView();
}
ListViewBase listView = CreateCarouselListLayout(CarouselItemsLayout.Orientation);

FindScrollViewer(listView);

Expand Down Expand Up @@ -174,13 +164,13 @@ void UpdateIsSwipeEnabled()

ListViewBase.IsSwipeEnabled = CarouselView.IsSwipeEnabled;

switch (Layout)
switch (CarouselItemsLayout.Orientation)
{
case LinearItemsLayout listItemsLayout when listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal:
case ItemsLayoutOrientation.Horizontal:
ScrollViewer.SetHorizontalScrollMode(ListViewBase, CarouselView.IsSwipeEnabled ? ScrollMode.Auto : ScrollMode.Disabled);
ScrollViewer.SetHorizontalScrollBarVisibility(ListViewBase, CarouselView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Disabled);
break;
case LinearItemsLayout listItemsLayout when listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical:
case ItemsLayoutOrientation.Vertical:
ScrollViewer.SetVerticalScrollMode(ListViewBase, CarouselView.IsSwipeEnabled ? ScrollMode.Auto : ScrollMode.Disabled);
ScrollViewer.SetVerticalScrollBarVisibility(ListViewBase, CarouselView.IsSwipeEnabled ? WScrollBarVisibility.Auto : WScrollBarVisibility.Disabled);
break;
Expand All @@ -197,45 +187,36 @@ void UpdateItemSpacing()
{
UpdateItemsSource();

if (Layout is LinearItemsLayout listItemsLayout)
{
var itemSpacing = listItemsLayout.ItemSpacing;
if (listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.Padding = new Windows.UI.Xaml.Thickness(0, 0, itemSpacing, 0);
var itemSpacing = CarouselItemsLayout.ItemSpacing;
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.Padding = new Windows.UI.Xaml.Thickness(0, 0, itemSpacing, 0);

if (listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.Padding = new Windows.UI.Xaml.Thickness(0, 0, 0, itemSpacing);
}
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.Padding = new Windows.UI.Xaml.Thickness(0, 0, 0, itemSpacing);
}

void UpdateSnapPointsType()
{
if (_scrollViewer == null)
return;

if (Layout is LinearItemsLayout listItemsLayout)
{
if (listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.HorizontalSnapPointsType = GetWindowsSnapPointsType(listItemsLayout.SnapPointsType);
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.HorizontalSnapPointsType = GetWindowsSnapPointsType(CarouselItemsLayout.SnapPointsType);

if (listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.VerticalSnapPointsType = GetWindowsSnapPointsType(listItemsLayout.SnapPointsType);
}
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.VerticalSnapPointsType = GetWindowsSnapPointsType(CarouselItemsLayout.SnapPointsType);
}

void UpdateSnapPointsAlignment()
{
if (_scrollViewer == null)
return;

if (Layout is LinearItemsLayout listItemsLayout)
{
if (listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.HorizontalSnapPointsAlignment = GetWindowsSnapPointsAlignment(listItemsLayout.SnapPointsAlignment);
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
_scrollViewer.HorizontalSnapPointsAlignment = GetWindowsSnapPointsAlignment(CarouselItemsLayout.SnapPointsAlignment);

if (listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.VerticalSnapPointsAlignment = GetWindowsSnapPointsAlignment(listItemsLayout.SnapPointsAlignment);
}
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
_scrollViewer.VerticalSnapPointsAlignment = GetWindowsSnapPointsAlignment(CarouselItemsLayout.SnapPointsAlignment);
}

ListViewBase CreateCarouselListLayout(ItemsLayoutOrientation layoutOrientation)
Expand Down Expand Up @@ -265,10 +246,10 @@ double GetItemWidth()
{
var itemWidth = ActualWidth;

if (Layout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
{
var numberOfVisibleItems = CarouselView.NumberOfSideItems * 2 + 1;
itemWidth = (ActualWidth - CarouselView.PeekAreaInsets.Left - CarouselView.PeekAreaInsets.Right - listItemsLayout.ItemSpacing) / numberOfVisibleItems;
itemWidth = (ActualWidth - CarouselView.PeekAreaInsets.Left - CarouselView.PeekAreaInsets.Right - CarouselItemsLayout.ItemSpacing) / numberOfVisibleItems;
}

return Math.Max(itemWidth, 0);
Expand All @@ -278,27 +259,24 @@ double GetItemHeight()
{
var itemHeight = ActualHeight;

if (Layout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
{
var numberOfVisibleItems = CarouselView.NumberOfSideItems * 2 + 1;
itemHeight = (ActualHeight - CarouselView.PeekAreaInsets.Top - CarouselView.PeekAreaInsets.Bottom - listItemsLayout.ItemSpacing) / numberOfVisibleItems;
itemHeight = (ActualHeight - CarouselView.PeekAreaInsets.Top - CarouselView.PeekAreaInsets.Bottom - CarouselItemsLayout.ItemSpacing) / numberOfVisibleItems;
}

return Math.Max(itemHeight, 0);
}

Thickness GetItemSpacing()
{
if (Layout is LinearItemsLayout listItemsLayout)
{
var itemSpacing = listItemsLayout.ItemSpacing;
var itemSpacing = CarouselItemsLayout.ItemSpacing;

if (listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
return new Thickness(itemSpacing, 0, 0, 0);
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
return new Thickness(itemSpacing, 0, 0, 0);

if (listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
return new Thickness(0, itemSpacing, 0, 0);
}
if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
return new Thickness(0, itemSpacing, 0, 0);

return new Thickness(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Xamarin.Forms.Platform.UWP
{
public class CollectionViewRenderer : GroupableItemsViewRenderer
public class CollectionViewRenderer : GroupableItemsViewRenderer<GroupableItemsView>
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,9 @@

namespace Xamarin.Forms.Platform.UWP
{
public class GroupableItemsViewRenderer : SelectableItemsViewRenderer
public class GroupableItemsViewRenderer<TItemsView> : SelectableItemsViewRenderer<TItemsView>
where TItemsView : GroupableItemsView
{
GroupableItemsView _groupableItemsView;

protected override void SetUpNewElement(ItemsView newElement)
{
_groupableItemsView = Element as GroupableItemsView;
base.SetUpNewElement(newElement);
}

protected override void TearDownOldElement(ItemsView oldElement)
{
base.TearDownOldElement(oldElement);
_groupableItemsView = null;
}

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs changedProperty)
{
base.OnElementPropertyChanged(sender, changedProperty);
Expand All @@ -33,15 +20,15 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

protected override CollectionViewSource CreateCollectionViewSource()
{
if (_groupableItemsView != null && _groupableItemsView.IsGrouped)
if (ItemsView != null && ItemsView.IsGrouped)
{
var itemTemplate = Element.ItemTemplate;
var itemsSource = Element.ItemsSource;

return new CollectionViewSource
{
Source = TemplatedItemSourceFactory.CreateGrouped(itemsSource, itemTemplate,
_groupableItemsView.GroupHeaderTemplate, _groupableItemsView.GroupFooterTemplate, Element),
ItemsView.GroupHeaderTemplate, ItemsView.GroupFooterTemplate, Element),
IsSourceGrouped = true,
ItemsPath = new Windows.UI.Xaml.PropertyPath(nameof(GroupTemplateContext.Items))
};
Expand Down
21 changes: 12 additions & 9 deletions Xamarin.Forms.Platform.UAP/CollectionView/ItemsViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Xamarin.Forms.Platform.UWP
{
public abstract class ItemsViewRenderer : ViewRenderer<ItemsView, ListViewBase>
public abstract class ItemsViewRenderer<TItemsView> : ViewRenderer<TItemsView, ListViewBase>
where TItemsView : ItemsView
{
protected CollectionViewSource CollectionViewSource;

Expand All @@ -25,9 +26,10 @@ public abstract class ItemsViewRenderer : ViewRenderer<ItemsView, ListViewBase>
FrameworkElement _emptyView;
View _formsEmptyView;

protected TItemsView ItemsView => Element;
protected ItemsControl ItemsControl { get; private set; }

protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> args)
protected override void OnElementChanged(ElementChangedEventArgs<TItemsView> args)
{
base.OnElementChanged(args);
TearDownOldElement(args.OldElement);
Expand All @@ -38,30 +40,31 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
{
base.OnElementPropertyChanged(sender, changedProperty);

if (changedProperty.Is(ItemsView.ItemsSourceProperty))
if (changedProperty.Is(Xamarin.Forms.ItemsView.ItemsSourceProperty))
{
UpdateItemsSource();
}
else if (changedProperty.Is(ItemsView.ItemTemplateProperty))
else if (changedProperty.Is(Xamarin.Forms.ItemsView.ItemTemplateProperty))
{
UpdateItemTemplate();
}
else if (changedProperty.Is(ItemsView.HorizontalScrollBarVisibilityProperty))
else if (changedProperty.Is(Xamarin.Forms.ItemsView.HorizontalScrollBarVisibilityProperty))
{
UpdateHorizontalScrollBarVisibility();
}
else if (changedProperty.Is(ItemsView.VerticalScrollBarVisibilityProperty))
else if (changedProperty.Is(Xamarin.Forms.ItemsView.VerticalScrollBarVisibilityProperty))
{
UpdateVerticalScrollBarVisibility();
}
else if (changedProperty.IsOneOf(ItemsView.EmptyViewProperty, ItemsView.EmptyViewTemplateProperty))
else if (changedProperty.IsOneOf(Xamarin.Forms.ItemsView.EmptyViewProperty,
Xamarin.Forms.ItemsView.EmptyViewTemplateProperty))
{
UpdateEmptyView();
}
}

protected abstract ListViewBase SelectListViewBase();
protected abstract void HandleLayoutPropertyChange(PropertyChangedEventArgs property);
protected abstract void HandleLayoutPropertyChanged(PropertyChangedEventArgs property);
protected abstract IItemsLayout Layout { get; }

protected virtual void UpdateItemsSource()
Expand Down Expand Up @@ -159,7 +162,7 @@ protected virtual void UpdateItemTemplate()

void LayoutPropertyChanged(object sender, PropertyChangedEventArgs property)
{
HandleLayoutPropertyChange(property);
HandleLayoutPropertyChanged(property);
}

protected virtual void SetUpNewElement(ItemsView newElement)
Expand Down
Loading

0 comments on commit a47a6e3

Please sign in to comment.