--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.Forms.Core.UITests;
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+#if UITEST
+ [Category(UITestCategories.CollectionView)]
+#endif
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 7519, "ItemSpacing not working on LinearLayout",
+ PlatformAffected.All)]
+ public class Issue7519 : TestNavigationPage
+ {
+ protected override void Init()
+ {
+#if APP
+ FlagTestHelpers.SetCollectionViewTestFlag();
+ PushAsync(new Issue7519Xaml());
+#endif
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:d="http://xamarin.com/schemas/2014/forms/design"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ x:Class="Xamarin.Forms.Controls.Issues.Issue7519Xaml">
+ <ContentPage.Resources>
+ <ResourceDictionary>
+ <DataTemplate x:Key="_7519Template">
+ <Frame HeightRequest="200" WidthRequest="200" BackgroundColor="ForestGreen">
+ <Label Text="{Binding Name}" VerticalOptions="Center" HorizontalOptions="Center" TextColor="White" />
+ </Frame>
+ </DataTemplate>
+ </ResourceDictionary>
+ </ContentPage.Resources>
+
+ <ContentPage.Content>
+ <StackLayout>
+
+ <Label Text="The CollectionView and CarouselView below should scroll horizontally and have 20 points of space between their items. If not, this test has failed."/>
+
+ <CollectionView ItemsSource="{Binding Items}" ItemTemplate="{StaticResource _7519Template}" Margin="20">
+ <CollectionView.ItemsLayout>
+ <LinearItemsLayout ItemSpacing="20" Orientation="Horizontal"/>
+ </CollectionView.ItemsLayout>
+ </CollectionView>
+
+ <CarouselView ItemsSource="{Binding Items}" ItemTemplate="{StaticResource _7519Template}" Margin="20">
+ <CarouselView.ItemsLayout>
+ <LinearItemsLayout ItemSpacing="20" Orientation="Horizontal" />
+ </CarouselView.ItemsLayout>
+ </CarouselView>
+
+ </StackLayout>
+ </ContentPage.Content>
+</ContentPage>
\ No newline at end of file
--- /dev/null
+using System.Collections.Generic;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.Xaml;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+#if APP
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ public partial class Issue7519Xaml : ContentPage
+ {
+ public Issue7519Xaml()
+ {
+ InitializeComponent();
+
+ var items = new List<_7519ItemModel>()
+ {
+ new _7519ItemModel {Name = "Item 1"},
+ new _7519ItemModel {Name = "Item 2"},
+ new _7519ItemModel {Name = "Item 3"},
+ new _7519ItemModel {Name = "Item 4"},
+ new _7519ItemModel {Name = "Item 5"},
+ new _7519ItemModel {Name = "Item 6"},
+ new _7519ItemModel {Name = "Item 7"},
+ };
+
+ BindingContext = new _7519Model { Items = items };
+ }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class _7519Model
+ {
+ public List<_7519ItemModel> Items { get; set; }
+ }
+
+ [Preserve(AllMembers = true)]
+ public class _7519ItemModel
+ {
+ public string Name { get; set; }
+ }
+
+#endif
+}
\ No newline at end of file
<Compile Include="$(MSBuildThisFileDirectory)Issue7049.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7061.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7111.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue7519.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml.cs">
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
<Compile Update="$(MSBuildThisFileDirectory)Issue6254.xaml.cs">
<DependentUpon>Issue6254.xaml</DependentUpon>
</Compile>
+ <Compile Update="C:\Users\hartez\Documents\Xamarin\Xamarin.Forms\Xamarin.Forms.Controls.Issues\Xamarin.Forms.Controls.Issues.Shared\Issue7519Xaml.xaml.cs">
+ <DependentUpon>Issue7519Xaml.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue1455.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </EmbeddedResource>
+ </ItemGroup>
</Project>
\ No newline at end of file
public static readonly BindableProperty ItemsLayoutProperty =
BindableProperty.Create(nameof(ItemsLayout), typeof(LinearItemsLayout), typeof(ItemsView),
- LinearItemsLayout.Horizontal);
+ LinearItemsLayout.CarouselDefault);
public LinearItemsLayout ItemsLayout
{
- get => (LinearItemsLayout)InternalItemsLayout;
- set => InternalItemsLayout = value;
+ get => (LinearItemsLayout)GetValue(ItemsLayoutProperty);
+ set => SetValue(ItemsLayoutProperty, value);
}
public event EventHandler<CurrentItemChangedEventArgs> CurrentItemChanged;
public static readonly IItemsLayout Vertical = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
public static readonly IItemsLayout Horizontal = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);
- // TODO hartez 2018/08/29 20:31:54 Need something like these previous two, but as a carousel default
+ internal static readonly LinearItemsLayout CarouselDefault = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal)
+ {
+ SnapPointsAlignment = SnapPointsAlignment.Center, SnapPointsType = SnapPointsType.Mandatory
+ };
public static readonly BindableProperty ItemSpacingProperty =
BindableProperty.Create(nameof(ItemSpacing), typeof(double), typeof(LinearItemsLayout), default(double),
set => SetValue(FooterTemplateProperty, value);
}
- public static readonly BindableProperty ItemsLayoutProperty =
- BindableProperty.Create(nameof(ItemsLayout), typeof(IItemsLayout), typeof(ItemsView),
- LinearItemsLayout.Vertical);
+ public static readonly BindableProperty ItemsLayoutProperty = InternalItemsLayoutProperty;
public IItemsLayout ItemsLayout
{
public class CarouselViewRenderer : ItemsViewRenderer<ItemsView, ItemsViewAdapter<ItemsView, IItemsViewSource>, IItemsViewSource>
{
protected CarouselView Carousel;
- IItemsLayout _layout;
ItemDecoration _itemDecoration;
bool _isSwipeEnabled;
bool _isUpdatingPositionFromForms;
_itemDecoration.Dispose();
_itemDecoration = null;
}
-
- _layout = null;
}
base.Dispose(disposing);
return;
}
- _layout = Carousel.ItemsLayout;
-
UpdateIsSwipeEnabled();
UpdateInitialPosition();
UpdateItemSpacing();
protected override void UpdateItemSpacing()
{
- if (_layout == null)
+ if (ItemsLayout == null)
{
return;
}
RemoveItemDecoration(_itemDecoration);
}
- _itemDecoration = CreateSpacingDecoration(_layout);
+ _itemDecoration = CreateSpacingDecoration(ItemsLayout);
AddItemDecoration(_itemDecoration);
var adapter = GetAdapter();
base.UpdateItemSpacing();
}
-
protected override IItemsLayout GetItemsLayout()
{
return Carousel.ItemsLayout;
{
var itemWidth = Width;
- if (_layout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
+ 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;
{
var itemHeight = Height;
- if (_layout is LinearItemsLayout listItemsLayout && listItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
+ 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;
bool _disposed;
protected TItemsView ItemsView;
+ protected IItemsLayout ItemsLayout { get; private set; }
- IItemsLayout _layout;
SnapManager _snapManager;
ScrollHelper _scrollHelper;
RecyclerViewScrollListener<TItemsView, TItemsViewSource> _recyclerViewScrollListener;
UpdateItemsSource();
- _layout = GetItemsLayout();
- SetLayoutManager(SelectLayoutManager(_layout));
+ ItemsLayout = GetItemsLayout();
+ SetLayoutManager(SelectLayoutManager(ItemsLayout));
UpdateSnapBehavior();
UpdateBackgroundColor();
UpdateVerticalScrollBarVisibility();
// Keep track of the ItemsLayout's property changes
- if (_layout != null)
+ if (ItemsLayout != null)
{
- _layout.PropertyChanged += LayoutPropertyChanged;
+ ItemsLayout.PropertyChanged += LayoutPropertyChanged;
}
// Listen for ScrollTo requests
}
// Stop listening for layout property changes
- if (_layout != null)
+ if (ItemsLayout != null)
{
- _layout.PropertyChanged -= LayoutPropertyChanged;
+ ItemsLayout.PropertyChanged -= LayoutPropertyChanged;
}
// Stop listening for property changes
{
if (GetLayoutManager() is GridLayoutManager gridLayoutManager)
{
- gridLayoutManager.SpanCount = ((GridItemsLayout)_layout).Span;
+ gridLayoutManager.SpanCount = ((GridItemsLayout)ItemsLayout).Span;
}
}
- else if (propertyChanged.IsOneOf(ItemsLayout.SnapPointsTypeProperty, ItemsLayout.SnapPointsAlignmentProperty))
+ else if (propertyChanged.IsOneOf(Xamarin.Forms.ItemsLayout.SnapPointsTypeProperty, Xamarin.Forms.ItemsLayout.SnapPointsAlignmentProperty))
{
UpdateSnapBehavior();
}
{
if (_snapManager == null)
{
- _snapManager = new SnapManager(_layout, this);
+ _snapManager = new SnapManager(ItemsLayout, this);
}
return _snapManager;
}
protected virtual void UpdateItemSpacing()
{
- if (_layout == null)
+ if (ItemsLayout == null)
{
return;
}
RemoveItemDecoration(_itemDecoration);
}
- _itemDecoration = CreateSpacingDecoration(_layout);
+ _itemDecoration = CreateSpacingDecoration(ItemsLayout);
AddItemDecoration(_itemDecoration);
}
else if (!showEmptyView && currAdapter != ItemsViewAdapter)
{
SwapAdapter(ItemsViewAdapter, true);
- SetLayoutManager(SelectLayoutManager(_layout));
+ SetLayoutManager(SelectLayoutManager(ItemsLayout));
}
}