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.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
samhouts committed Mar 19, 2019
2 parents 21eb50b + 0a7e735 commit b20afe4
Show file tree
Hide file tree
Showing 45 changed files with 656 additions and 325 deletions.
4 changes: 0 additions & 4 deletions .nuspec/Xamarin.Forms.Maps.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,5 @@
<file src="..\Xamarin.Forms.Maps\bin\$Configuration$\netstandard2.0\Xamarin.Forms.Maps.dll" target="lib\tizen40" />
<file src="..\docs\Xamarin.Forms.Maps.xml" target="lib\tizen40" />

<!-- Xaml Design-time Stuff -->
<file src="..\Xamarin.Forms.Maps.Design\bin\$Configuration$\Xamarin.Forms.Maps.Design.dll" target="lib\netstandard2.0\Design" />
<file src="..\Xamarin.Forms.Maps.Design\bin\$Configuration$\Xamarin.Forms.Maps.Design.dll" target="lib\netstandard1.0\Design" />

</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static DataTemplate PhotoTemplate()
HeightRequest = 100, WidthRequest = 100,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Margin = new Thickness(2, 5, 2, 2),
AutomationId = "photo"
};

Expand All @@ -30,7 +31,8 @@ public static DataTemplate PhotoTemplate()
{
FontSize = 12,
HorizontalOptions = LayoutOptions.Fill,
HorizontalTextAlignment = TextAlignment.Center
HorizontalTextAlignment = TextAlignment.Center,
Margin = new Thickness(2, 0, 2, 2)
};

caption.SetBinding(Label.TextProperty, new Binding("Caption"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using System.Linq;
using Xamarin.Forms.Xaml;

namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.SelectionGalleries
Expand All @@ -14,9 +8,9 @@ public partial class PreselectedItemGallery : ContentPage
{
readonly DemoFilteredItemSource _demoFilteredItemSource = new DemoFilteredItemSource();

public PreselectedItemGallery ()
public PreselectedItemGallery()
{
InitializeComponent ();
InitializeComponent();

CollectionView.ItemTemplate = ExampleTemplates.PhotoTemplate();
CollectionView.ItemsSource = _demoFilteredItemSource.Items;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.SelectionGalleries.PreselectedItemsGallery">
<ContentPage.Content>
<StackLayout Margin="10">

<Label Text="The CollectionView below should have several items already selected."/>

<CollectionView x:Name="CollectionView" Grid.Row="3">
<CollectionView.ItemsLayout>
<GridItemsLayout Span="4" Orientation="Vertical"></GridItemsLayout>
</CollectionView.ItemsLayout>
</CollectionView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.SelectionGalleries
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PreselectedItemsGallery : ContentPage
{
readonly DemoFilteredItemSource _demoFilteredItemSource = new DemoFilteredItemSource();

public PreselectedItemsGallery()
{
InitializeComponent();

CollectionView.ItemTemplate = ExampleTemplates.PhotoTemplate();
CollectionView.ItemsSource = _demoFilteredItemSource.Items;

CollectionView.SelectedItems.Add(_demoFilteredItemSource.Items.Skip(2).First());
CollectionView.SelectedItems.Add(_demoFilteredItemSource.Items.Skip(4).First());
CollectionView.SelectedItems.Add(_demoFilteredItemSource.Items.Skip(5).First());

CollectionView.SelectionMode = SelectionMode.Multiple;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public SelectionGallery()
new SelectionModeGallery(), Navigation),
GalleryBuilder.NavButton("Preselected Item", () =>
new PreselectedItemGallery(), Navigation),
GalleryBuilder.NavButton("Preselected Items", () =>
new PreselectedItemsGallery(), Navigation),
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ void UpdateSelectionInfoCommand()
{
var current = "[none]";

if (CollectionView.SelectedItem != null)
if(CollectionView.SelectionMode == SelectionMode.Multiple)
{
current = ToList(CollectionView?.SelectedItems);
}
else if (CollectionView.SelectionMode == SelectionMode.Single)
{
current = ((CollectionViewGalleryTestItem)CollectionView?.SelectedItem)?.Caption;
}
Expand Down
6 changes: 6 additions & 0 deletions Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
</Compile>
<Compile Update="GalleryPages\CollectionViewGalleries\EmptyViewGalleries\EmptyViewLoadSimulateGallery.xaml.cs">
<DependentUpon>EmptyViewLoadSimulateGallery.xaml</DependentUpon>
</Compile>
<Compile Update="GalleryPages\CollectionViewGalleries\SelectionGalleries\PreselectedItemsGallery.xaml.cs">
<DependentUpon>PreselectedItemsGallery.xaml</DependentUpon>
</Compile>
<Compile Update="GalleryPages\VisualStateManagerGalleries\OnPlatformExample.xaml.cs">
<DependentUpon>OnPlatformExample.xaml</DependentUpon>
Expand All @@ -53,6 +56,9 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="GalleryPages\CollectionViewGalleries\EmptyViewGalleries\EmptyViewSwapGallery.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="GalleryPages\CollectionViewGalleries\SelectionGalleries\PreselectedItemsGallery.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="GalleryPages\MapWithItemsSourceGallery.xaml">
Expand Down
92 changes: 87 additions & 5 deletions Xamarin.Forms.Core/Items/SelectableItemsView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace Xamarin.Forms
Expand All @@ -7,25 +8,41 @@ public class SelectableItemsView : ItemsView
{
public static readonly BindableProperty SelectionModeProperty =
BindableProperty.Create(nameof(SelectionMode), typeof(SelectionMode), typeof(SelectableItemsView),
SelectionMode.None);
SelectionMode.None, propertyChanged: SelectionModePropertyChanged );

public static readonly BindableProperty SelectedItemProperty =
BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(SelectableItemsView), default(object),
propertyChanged: SelectedItemPropertyChanged);

static readonly BindablePropertyKey SelectedItemsPropertyKey =
BindableProperty.CreateReadOnly(nameof(SelectedItems), typeof(IList<object>), typeof(SelectableItemsView), null);

public static readonly BindableProperty SelectedItemsProperty = SelectedItemsPropertyKey.BindableProperty;

public static readonly BindableProperty SelectionChangedCommandProperty =
BindableProperty.Create(nameof(SelectionChangedCommand), typeof(ICommand), typeof(SelectableItemsView));

public static readonly BindableProperty SelectionChangedCommandParameterProperty =
BindableProperty.Create(nameof(SelectionChangedCommandParameter), typeof(object),
typeof(SelectableItemsView));

public SelectableItemsView()
{
var selectionList = new SelectionList(this);
SetValue(SelectedItemsPropertyKey, selectionList);
}

public object SelectedItem
{
get => GetValue(SelectedItemProperty);
set => SetValue(SelectedItemProperty, value);
}

public IList<object> SelectedItems
{
get => (IList<object>)GetValue(SelectedItemsProperty);
}

public ICommand SelectionChangedCommand
{
get => (ICommand)GetValue(SelectionChangedCommandProperty);
Expand All @@ -50,12 +67,14 @@ protected virtual void OnSelectionChanged(SelectionChangedEventArgs args)
{
}

static void SelectedItemPropertyChanged(BindableObject bindable, object oldValue, object newValue)
internal void SelectedItemsPropertyChanged(IList<object> oldSelection, IList<object> newSelection)
{
var selectableItemsView = (SelectableItemsView)bindable;

var args = new SelectionChangedEventArgs(oldValue, newValue);
SelectionPropertyChanged(this, new SelectionChangedEventArgs(oldSelection, newSelection));
OnPropertyChanged(SelectedItemsProperty.PropertyName);
}

static void SelectionPropertyChanged(SelectableItemsView selectableItemsView, SelectionChangedEventArgs args)
{
var command = selectableItemsView.SelectionChangedCommand;

if (command != null)
Expand All @@ -72,5 +91,68 @@ static void SelectedItemPropertyChanged(BindableObject bindable, object oldValue

selectableItemsView.OnSelectionChanged(args);
}

static void SelectedItemPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var selectableItemsView = (SelectableItemsView)bindable;

var args = new SelectionChangedEventArgs(oldValue, newValue);

SelectionPropertyChanged(selectableItemsView, args);
}

static void SelectionModePropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var selectableItemsView = (SelectableItemsView)bindable;

var oldMode = (SelectionMode)oldValue;
var newMode = (SelectionMode)newValue;

IList<object> previousSelection = new List<object>();
IList<object> newSelection = new List<object>();

switch (oldMode)
{
case SelectionMode.None:
break;
case SelectionMode.Single:
if (selectableItemsView.SelectedItem != null)
{
previousSelection.Add(selectableItemsView.SelectedItem);
}
break;
case SelectionMode.Multiple:
previousSelection = selectableItemsView.SelectedItems;
break;
}

switch (newMode)
{
case SelectionMode.None:
break;
case SelectionMode.Single:
if (selectableItemsView.SelectedItem != null)
{
newSelection.Add(selectableItemsView.SelectedItem);
}
break;
case SelectionMode.Multiple:
newSelection = selectableItemsView.SelectedItems;
break;
}

if (previousSelection.Count == newSelection.Count)
{
if (previousSelection.Count == 0 || (previousSelection[0] == newSelection[0]))
{
// Both selections are empty or have the same single item; no reason to signal a change
return;
}
}

var args = new SelectionChangedEventArgs(previousSelection, newSelection);

SelectionPropertyChanged(selectableItemsView, args);
}
}
}
6 changes: 3 additions & 3 deletions Xamarin.Forms.Core/Items/SelectionChangedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ internal SelectionChangedEventArgs(object previousSelection, object currentSelec
CurrentSelection = currentSelection != null ? new List<object>(1) { currentSelection } : s_empty;
}

internal SelectionChangedEventArgs(List<object> previousSelection, List<object> currentSelection)
internal SelectionChangedEventArgs(IList<object> previousSelection, IList<object> currentSelection)
{
PreviousSelection = previousSelection ?? throw new ArgumentNullException(nameof(previousSelection));
CurrentSelection = currentSelection ?? throw new ArgumentNullException(nameof(currentSelection));
PreviousSelection = new List<object>(previousSelection ?? throw new ArgumentNullException(nameof(previousSelection)));
CurrentSelection = new List<object>(currentSelection ?? throw new ArgumentNullException(nameof(currentSelection)));
}
}
}
Loading

0 comments on commit b20afe4

Please sign in to comment.