summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-04-26 15:35:52 -0400
committerJason Smith <jason.smith@xamarin.com>2016-04-26 15:35:52 -0400
commit409e10528495238a680c1bf3867a71f758b0d452 (patch)
tree0cb19f682b0b192ebad3dc0c77cfe32974abe09c /Xamarin.Forms.Core
parent9ae4ea3c82444561353eb77bf746f96cdbfb4583 (diff)
downloadxamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.tar.gz
xamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.tar.bz2
xamarin-forms-409e10528495238a680c1bf3867a71f758b0d452.zip
Carousel clean (#135)
CarouselView moving to preview repo
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/CarouselView.cs108
-rw-r--r--Xamarin.Forms.Core/ICarouselViewController.cs10
-rw-r--r--Xamarin.Forms.Core/ItemsViewSimple.cs356
-rw-r--r--Xamarin.Forms.Core/Xamarin.Forms.Core.csproj3
4 files changed, 0 insertions, 477 deletions
diff --git a/Xamarin.Forms.Core/CarouselView.cs b/Xamarin.Forms.Core/CarouselView.cs
deleted file mode 100644
index c74463d3..00000000
--- a/Xamarin.Forms.Core/CarouselView.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-using System;
-using Xamarin.Forms.Platform;
-
-namespace Xamarin.Forms
-{
- [RenderWith(typeof(_CarouselViewRenderer))]
- public class CarouselView : ItemsView, ICarouselViewController
- {
- public static readonly BindableProperty PositionProperty =
- BindableProperty.Create(
- propertyName: nameof(Position),
- returnType: typeof(int),
- declaringType: typeof(CarouselView),
- defaultValue: 0,
- defaultBindingMode: BindingMode.TwoWay
- );
-
- public static readonly BindableProperty ItemProperty =
- BindableProperty.Create(
- propertyName: nameof(Item),
- returnType: typeof(object),
- declaringType: typeof(CarouselView),
- defaultValue: null,
- defaultBindingMode: BindingMode.TwoWay
- );
-
- object _lastItem;
- int _lastPosition;
-
- public CarouselView()
- {
- _lastPosition = 0;
- _lastItem = null;
- VerticalOptions = LayoutOptions.FillAndExpand;
- HorizontalOptions = LayoutOptions.FillAndExpand;
- }
-
- object GetItem(int position)
- {
- var controller = (IItemViewController)this;
- object item = controller.GetItem(position);
- return item;
- }
-
- // non-public bc unable to implement on iOS
- internal event EventHandler<ItemVisibilityEventArgs> ItemAppearing;
- internal event EventHandler<ItemVisibilityEventArgs> ItemDisappearing;
-
- public int Position
- {
- get
- {
- return (int)GetValue(PositionProperty);
- }
- set
- {
- SetValue(PositionProperty, value);
- }
- }
- public object Item
- {
- get
- {
- return GetValue(ItemProperty);
- }
- internal set
- {
- SetValue(ItemProperty, value);
- }
- }
-
- public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;
- public event EventHandler<SelectedPositionChangedEventArgs> PositionSelected;
-
- protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
- {
- var minimumSize = new Size(40, 40);
- return new SizeRequest(minimumSize, minimumSize);
- }
-
- void ICarouselViewController.SendPositionAppearing(int position)
- {
- ItemAppearing?.Invoke(this, new ItemVisibilityEventArgs(GetItem(position)));
- }
- void ICarouselViewController.SendPositionDisappearing(int position)
- {
- ItemDisappearing?.Invoke(this, new ItemVisibilityEventArgs(GetItem(position)));
- }
- void ICarouselViewController.SendSelectedItemChanged(object item)
- {
- if (item.Equals(_lastItem))
- return;
- _lastItem = item;
-
- Item = item;
- ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(item));
- }
- void ICarouselViewController.SendSelectedPositionChanged(int position)
- {
- if (_lastPosition == position)
- return;
- _lastPosition = position;
-
- Item = ((IItemViewController)this).GetItem(position);
- PositionSelected?.Invoke(this, new SelectedPositionChangedEventArgs(position));
- }
- }
-} \ No newline at end of file
diff --git a/Xamarin.Forms.Core/ICarouselViewController.cs b/Xamarin.Forms.Core/ICarouselViewController.cs
deleted file mode 100644
index f59bc3d3..00000000
--- a/Xamarin.Forms.Core/ICarouselViewController.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Xamarin.Forms
-{
- public interface ICarouselViewController : IItemViewController
- {
- void SendPositionAppearing(int position);
- void SendPositionDisappearing(int position);
- void SendSelectedItemChanged(object item);
- void SendSelectedPositionChanged(int position);
- }
-} \ No newline at end of file
diff --git a/Xamarin.Forms.Core/ItemsViewSimple.cs b/Xamarin.Forms.Core/ItemsViewSimple.cs
deleted file mode 100644
index 8ad82b7f..00000000
--- a/Xamarin.Forms.Core/ItemsViewSimple.cs
+++ /dev/null
@@ -1,356 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Linq;
-using System.Runtime.CompilerServices;
-
-namespace Xamarin.Forms
-{
- public abstract class ItemsView : View, IItemViewController
- {
- public static readonly BindableProperty ItemsSourceProperty =
- BindableProperty.Create(
- propertyName: "ItemsSource",
- returnType: typeof(IEnumerable),
- declaringType: typeof(ItemsView),
- defaultValue: Enumerable.Empty<object>()
- );
-
- public static readonly BindableProperty ItemTemplateProperty =
- BindableProperty.Create(
- propertyName: "ItemTemplate",
- returnType: typeof(DataTemplate),
- declaringType: typeof(ItemsView)
- );
-
- ItemSource _itemSource;
-
- internal ItemsView()
- {
- }
-
- public IEnumerable ItemsSource
- {
- get
- {
- return (IEnumerable)GetValue(ItemsSourceProperty);
- }
- set
- {
- SetValue(ItemsSourceProperty, value);
- }
- }
-
- public DataTemplate ItemTemplate
- {
- get
- {
- return (DataTemplate)GetValue(ItemTemplateProperty);
- }
- set
- {
- SetValue(ItemTemplateProperty, value);
- }
- }
-
- int IItemViewController.Count => _itemSource.Count;
-
- void IItemViewController.BindView(View view, object item)
- {
- view.BindingContext = item;
- }
-
- View IItemViewController.CreateView(object type)
- {
- var dataTemplate = (DataTemplate)type;
- object content = dataTemplate.CreateContent();
- var view = (View)content;
- view.Parent = this;
- return view;
- }
-
- object IItemViewController.GetItem(int index) => _itemSource[index];
-
- object IItemViewController.GetItemType(object item)
- {
- DataTemplate dataTemplate = ItemTemplate;
- var dataTemplateSelector = dataTemplate as DataTemplateSelector;
- if (dataTemplateSelector != null)
- dataTemplate = dataTemplateSelector.SelectTemplate(item, this);
-
- if (item == null)
- throw new ArgumentException($"No DataTemplate resolved for item: {item}.");
-
- return dataTemplate;
- }
-
- protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- if (propertyName == nameof(ItemsSource))
- {
- var itemsSource = ItemsSource;
- if (itemsSource == null)
- itemsSource = Enumerable.Empty<object>();
-
- // abstract enumerable, IList, IList<T>, and IReadOnlyList<T>
- _itemSource = new ItemSource(itemsSource);
-
- // subscribe to collection changed events
- var dynamicItemSource = _itemSource as INotifyCollectionChanged;
- if (dynamicItemSource != null)
- {
- new WeakNotifyCollectionChanged(this, dynamicItemSource);
- }
- }
-
- base.OnPropertyChanged(propertyName);
- }
-
- internal event NotifyCollectionChangedEventHandler CollectionChanged;
-
- internal void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- CollectionChanged?.Invoke(sender, e);
- }
-
- sealed class WeakNotifyCollectionChanged
- {
- readonly WeakReference<INotifyCollectionChanged> _weakCollection;
- readonly WeakReference<ItemsView> _weakSource;
-
- public WeakNotifyCollectionChanged(ItemsView source, INotifyCollectionChanged incc)
- {
- incc.CollectionChanged += OnCollectionChanged;
-
- _weakSource = new WeakReference<ItemsView>(source);
- _weakCollection = new WeakReference<INotifyCollectionChanged>(incc);
- }
-
- void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- ItemsView source;
- if (!_weakSource.TryGetTarget(out source))
- {
- INotifyCollectionChanged collection;
- if (_weakCollection.TryGetTarget(out collection))
- collection.CollectionChanged -= OnCollectionChanged;
-
- return;
- }
-
- source.OnCollectionChanged(sender, e);
- }
- }
-
- sealed class ItemSource : IEnumerable<object>, INotifyCollectionChanged
- {
- IndexableCollection _indexable;
-
- internal ItemSource(IEnumerable enumerable)
- {
- _indexable = new IndexableCollection(enumerable);
- var dynamicItemSource = enumerable as INotifyCollectionChanged;
- if (dynamicItemSource != null)
- dynamicItemSource.CollectionChanged += OnCollectionChanged;
- }
-
- public int Count => _indexable.Count;
-
- public IEnumerable Enumerable => _indexable.Enumerable;
-
- public object this[int index]
- {
- get
- {
- // madness ported from listProxy
- CollectionSynchronizationContext syncContext = SyncContext;
- if (syncContext != null)
- {
- object value = null;
- syncContext.Callback(Enumerable, SyncContext.Context, () => value = _indexable[index], false);
-
- return value;
- }
-
- return _indexable[index];
- }
- }
-
- CollectionSynchronizationContext SyncContext
- {
- get
- {
- CollectionSynchronizationContext syncContext;
- BindingBase.TryGetSynchronizedCollection(Enumerable, out syncContext);
- return syncContext;
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- IEnumerator<object> IEnumerable<object>.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public event NotifyCollectionChangedEventHandler CollectionChanged;
-
- public Enumerator GetEnumerator()
- {
- return new Enumerator(this);
- }
-
- void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- Action onCollectionChanged = () =>
- {
- if (CollectionChanged != null)
- CollectionChanged(this, e);
- };
-
- // madness ported from listProxy
- CollectionSynchronizationContext syncContext = SyncContext;
- if (syncContext != null)
- {
- syncContext.Callback(Enumerable, syncContext.Context, () => Device.BeginInvokeOnMainThread(onCollectionChanged), false);
- }
-
- else if (Device.IsInvokeRequired)
- Device.BeginInvokeOnMainThread(onCollectionChanged);
-
- else
- onCollectionChanged();
- }
-
- internal struct Enumerator : IEnumerator<object>
- {
- readonly ItemSource _itemSource;
- int _index;
-
- internal Enumerator(ItemSource itemSource) : this()
- {
- _itemSource = itemSource;
- }
-
- public bool MoveNext()
- {
- if (_index == _itemSource.Count)
- return false;
-
- Current = _itemSource[_index++];
- return true;
- }
-
- public object Current
- {
- get; private set;
- }
-
- public void Reset()
- {
- Current = null;
- _index = 0;
- }
-
- public void Dispose()
- {
- }
- }
-
- struct IndexableCollection : IEnumerable<object>
- {
- internal IndexableCollection(IEnumerable list)
- {
- Enumerable = list;
-
- if (list is IList)
- return;
-
- if (list is IList<object>)
- return;
-
- if (list is IReadOnlyList<object>)
- return;
-
- Enumerable = list.Cast<object>().ToArray();
- }
-
- internal IEnumerable Enumerable
- {
- get;
- }
-
- internal int Count
- {
- get
- {
- var list = Enumerable as IList;
- if (list != null)
- return list.Count;
-
- var listOf = Enumerable as IList<object>;
- if (listOf != null)
- return listOf.Count;
-
- var readOnlyList = (IReadOnlyList<object>)Enumerable;
- return readOnlyList.Count;
- }
- }
-
- internal object this[int index]
- {
- get
- {
- var list = Enumerable as IList;
- if (list != null)
- return list[index];
-
- var listOf = Enumerable as IList<object>;
- if (listOf != null)
- return listOf[index];
-
- var readOnlyList = (IReadOnlyList<object>)Enumerable;
- return readOnlyList[index];
- }
- }
-
- internal int IndexOf(object item)
- {
- var list = Enumerable as IList;
- if (list != null)
- return list.IndexOf(item);
-
- var listOf = Enumerable as IList<object>;
- if (listOf != null)
- return listOf.IndexOf(item);
-
- var readOnlyList = (IReadOnlyList<object>)Enumerable;
- return readOnlyList.IndexOf(item);
- }
-
- public IEnumerator<object> GetEnumerator()
- {
- var list = Enumerable as IList;
- if (list != null)
- return list.Cast<object>().GetEnumerator();
-
- var listOf = Enumerable as IList<object>;
- if (listOf != null)
- return listOf.GetEnumerator();
-
- var readOnlyList = (IReadOnlyList<object>)Enumerable;
- return readOnlyList.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
index d8a3772c..dbd109a6 100644
--- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
+++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
@@ -62,7 +62,6 @@
<Compile Include="BindingTypeConverter.cs" />
<Compile Include="BoundsConstraint.cs" />
<Compile Include="BoundsTypeConverter.cs" />
- <Compile Include="CarouselView.cs" />
<Compile Include="CastingEnumerator.cs" />
<Compile Include="Cells\EntryCell.cs" />
<Compile Include="Cells\ImageCell.cs" />
@@ -110,7 +109,6 @@
<Compile Include="HandlerAttribute.cs" />
<Compile Include="HtmlWebViewSource.cs" />
<Compile Include="IButtonController.cs" />
- <Compile Include="ICarouselViewController.cs" />
<Compile Include="IControlTemplated.cs" />
<Compile Include="IDefinition.cs" />
<Compile Include="IEffectControlProvider.cs" />
@@ -138,7 +136,6 @@
<Compile Include="IResourcesProvider.cs" />
<Compile Include="IRootObjectProvider.cs" />
<Compile Include="IScrollViewController.cs" />
- <Compile Include="ItemsViewSimple.cs" />
<Compile Include="ItemTappedEventArgs.cs" />
<Compile Include="ItemVisibilityEventArgs.cs" />
<Compile Include="IValueConverterProvider.cs" />