summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkingces95 <kingces95@users.noreply.github.com>2016-04-18 11:39:23 -0700
committerSamantha Houts <samantha@teamredwall.com>2016-04-18 11:39:23 -0700
commit0d57b35f21b9499876c65c7be6d11637543605aa (patch)
tree93ac3a3b3dd699d11f6a5dd7a3864bc32b8eee8e
parent8f5c5e4e06b1ec5b781a6c20d75a67c8d82234f2 (diff)
downloadxamarin-forms-0d57b35f21b9499876c65c7be6d11637543605aa.tar.gz
xamarin-forms-0d57b35f21b9499876c65c7be6d11637543605aa.tar.bz2
xamarin-forms-0d57b35f21b9499876c65c7be6d11637543605aa.zip
CarouselView Fixes (#101)
* Fix CarouselView.Item * CarouselView formatting * Move ItemsView.Count to IItemsViewController * Remove dead code: CarouselView.IndexOf * CarouselView re-layout subviews on resize. * Add ItemTemplate to resources.xaml on UWP * Docs
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs36
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/CarouselViewGallery.cs11
-rw-r--r--Xamarin.Forms.Core/CarouselView.cs17
-rw-r--r--Xamarin.Forms.Core/IItemViewController.cs1
-rw-r--r--Xamarin.Forms.Core/ItemsViewSimple.cs19
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs7
-rw-r--r--Xamarin.Forms.Platform.UAP/Resources.xaml4
-rw-r--r--Xamarin.Forms.Platform.WinRT/CarouselViewRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/CarouselViewRenderer.cs27
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/IItemViewController.xml16
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/ItemsView.xml32
11 files changed, 104 insertions, 74 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs
index 9c7d9cd5..6288caa8 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/CarouselViewGallery.cs
@@ -58,6 +58,7 @@ namespace Xamarin.Forms.Controls
return galleryPage;
}
public void Screenshot(string message) => _app.Screenshot(message);
+ public IApp App => _app;
}
public class CarouselViewGallery : IGalleryPage
@@ -256,22 +257,31 @@ namespace Xamarin.Forms.Controls
Assert.AreNotEqual(0, CarouselViewGallery.InitialItemId);
Assert.AreEqual(CarouselViewGallery.InitialItemId, carousel.ItemId);
- // programatic jump to first/last
- carousel.Last();
- carousel.First();
+ gallery.App.SetOrientationPortrait();
- // programatic step to page
- carousel.StepToLast();
- carousel.StepToFirst();
+ for (var i = 0; i < 2; i++)
+ {
+ // programatic jump to first/last
+ carousel.Last();
+ carousel.First();
+
+ // programatic step to page
+ carousel.StepToLast();
+ carousel.StepToFirst();
- // swiping
- carousel.SwipeToLast();
- carousel.SwipeNext(); // test swipe past end
- carousel.SwipeToFirst();
- carousel.SwipePrevious(); // test swipe past start
+ // swiping
+ carousel.SwipeToLast();
+ carousel.SwipeNext(); // test swipe past end
+ carousel.SwipeToFirst();
+ carousel.SwipePrevious(); // test swipe past start
- } catch (Exception e) {
- gallery.Screenshot(e.ToString());
+ gallery.App.SetOrientationLandscape();
+ }
+
+ gallery.Screenshot("End");
+ }
+ catch (Exception e) {
+ gallery.Screenshot("End");
throw e;
}
}
diff --git a/Xamarin.Forms.Controls/GalleryPages/CarouselViewGallery.cs b/Xamarin.Forms.Controls/GalleryPages/CarouselViewGallery.cs
index c5b431d6..c2e0ef7f 100644
--- a/Xamarin.Forms.Controls/GalleryPages/CarouselViewGallery.cs
+++ b/Xamarin.Forms.Controls/GalleryPages/CarouselViewGallery.cs
@@ -246,14 +246,19 @@ namespace Xamarin.Forms.Controls
_eventLog = CreateValue(string.Empty, "EventLog");
_carouselView.ItemSelected += (s, o) => {
- var selectedItem = ((Item)o.SelectedItem).Id;
- _selectedItem.Text = $"{selectedItem}";
+ var selectedItem = (Item)o.SelectedItem;
+ var selectedItemId = selectedItem.Id;
+ if (selectedItem != _carouselView.Item)
+ throw new Exception("CarouselView.Item != ItemSelected");
+ _selectedItem.Text = $"{selectedItemId}";
OnEvent("i");
};
_carouselView.PositionSelected += (s, o) => {
var selectedPosition = (int)o.SelectedPosition;
- _selectedPosition.Text = $"{selectedPosition}";
+ if (_items[selectedPosition] != _carouselView.Item)
+ throw new Exception("CarouselView.Item != Items[selectedPosition]");
+ _selectedPosition.Text = $"{selectedPosition}";
OnEvent("p");
};
diff --git a/Xamarin.Forms.Core/CarouselView.cs b/Xamarin.Forms.Core/CarouselView.cs
index b0be847f..68c387b6 100644
--- a/Xamarin.Forms.Core/CarouselView.cs
+++ b/Xamarin.Forms.Core/CarouselView.cs
@@ -24,10 +24,8 @@ namespace Xamarin.Forms
defaultBindingMode: BindingMode.TwoWay
);
- #region Fields
object _lastItem;
int _lastPosition;
- #endregion
public CarouselView()
{
@@ -37,14 +35,12 @@ namespace Xamarin.Forms
HorizontalOptions = LayoutOptions.FillAndExpand;
}
- #region Private Members
object GetItem(int position)
{
var controller = (IItemViewController)this;
object item = controller.GetItem(position);
return item;
}
- #endregion
// non-public bc unable to implement on iOS
internal event EventHandler<ItemVisibilityEventArgs> ItemAppearing;
@@ -55,9 +51,10 @@ namespace Xamarin.Forms
get { return (int)GetValue(PositionProperty); }
set { SetValue(PositionProperty, value); }
}
- public int Item
+ public object Item
{
- get { return (int)GetValue(ItemProperty); }
+ get { return GetValue(ItemProperty); }
+ internal set { SetValue(ItemProperty, value); }
}
public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;
@@ -81,16 +78,18 @@ namespace Xamarin.Forms
{
if (item.Equals(_lastItem))
return;
-
- ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(item));
_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));
}
}
diff --git a/Xamarin.Forms.Core/IItemViewController.cs b/Xamarin.Forms.Core/IItemViewController.cs
index 79f711e9..0876f602 100644
--- a/Xamarin.Forms.Core/IItemViewController.cs
+++ b/Xamarin.Forms.Core/IItemViewController.cs
@@ -6,5 +6,6 @@
View CreateView(object itemType);
object GetItem(int index);
object GetItemType(object item);
+ int Count { get; }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Core/ItemsViewSimple.cs b/Xamarin.Forms.Core/ItemsViewSimple.cs
index 51b9df7a..59858d22 100644
--- a/Xamarin.Forms.Core/ItemsViewSimple.cs
+++ b/Xamarin.Forms.Core/ItemsViewSimple.cs
@@ -30,8 +30,6 @@ namespace Xamarin.Forms
{
}
- public int Count => _itemSource.Count;
-
public IEnumerable ItemsSource
{
get { return (IEnumerable)GetValue(ItemsSourceProperty); }
@@ -44,6 +42,8 @@ namespace Xamarin.Forms
set { SetValue(ItemTemplateProperty, value); }
}
+ int IItemViewController.Count => _itemSource.Count;
+
void IItemViewController.BindView(View view, object item)
{
view.BindingContext = item;
@@ -192,21 +192,6 @@ namespace Xamarin.Forms
return new Enumerator(this);
}
- public int IndexOf(object item)
- {
- // madness ported from listProxy
- CollectionSynchronizationContext syncContext = SyncContext;
- if (syncContext != null)
- {
- int value = -1;
- syncContext.Callback(Enumerable, SyncContext.Context, () => value = _indexable.IndexOf(item), false);
-
- return value;
- }
-
- return _indexable.IndexOf(item);
- }
-
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Action onCollectionChanged = () =>
diff --git a/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
index 0056a1f8..55d9b0df 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/CarouselViewRenderer.cs
@@ -521,7 +521,7 @@ namespace Xamarin.Forms.Platform.Android
break;
case NotifyCollectionChangedAction.Remove:
- if (Element.Count == 0)
+ if (Controller.Count == 0)
throw new InvalidOperationException("CarouselView must retain a least one item.");
Adapter.NotifyItemRangeRemoved(
@@ -1189,8 +1189,9 @@ namespace Xamarin.Forms.Platform.Android
public override int ItemCount
{
- get {
- return Element.Count;
+ get
+ {
+ return Controller.Count;
}
}
public override int GetItemViewType(int position)
diff --git a/Xamarin.Forms.Platform.UAP/Resources.xaml b/Xamarin.Forms.Platform.UAP/Resources.xaml
index 23753c13..b66958bf 100644
--- a/Xamarin.Forms.Platform.UAP/Resources.xaml
+++ b/Xamarin.Forms.Platform.UAP/Resources.xaml
@@ -56,6 +56,10 @@
</Setter>
</Style>
+ <DataTemplate x:Key="ItemTemplate">
+ <uwp:ItemControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
+ </DataTemplate>
+
<ControlTemplate TargetType="ContentDialog" x:Key="MyContentDialogControlTemplate">
<Border x:Name="Container">
<Grid x:Name="LayoutRoot">
diff --git a/Xamarin.Forms.Platform.WinRT/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.WinRT/CarouselViewRenderer.cs
index 3e1fd096..e4ff754c 100644
--- a/Xamarin.Forms.Platform.WinRT/CarouselViewRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/CarouselViewRenderer.cs
@@ -45,7 +45,11 @@ namespace Xamarin.Forms.Platform.WinRT
{
if (_flipView == null)
{
- _flipView = new FlipView { IsSynchronizedWithCurrentItem = false, ItemTemplate = (WDataTemplate)WApp.Current.Resources["ItemTemplate"] };
+ _flipView = new FlipView
+ {
+ IsSynchronizedWithCurrentItem = false,
+ ItemTemplate = (WDataTemplate)WApp.Current.Resources["ItemTemplate"]
+ };
}
_flipView.ItemsSource = Element.ItemsSource;
@@ -89,7 +93,7 @@ namespace Xamarin.Forms.Platform.WinRT
break;
case NotifyCollectionChangedAction.Remove:
- if (Element.Count == 0)
+ if (Controller.Count == 0)
throw new InvalidOperationException("CarouselView must retain a least one item.");
if (e.OldStartingIndex < Element.Position)
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/CarouselViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/CarouselViewRenderer.cs
index 3efb316b..5bc2b8de 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/CarouselViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/CarouselViewRenderer.cs
@@ -55,16 +55,9 @@ namespace Xamarin.Forms.Platform.iOS
int _position;
CarouselViewController _controller;
+ RectangleF _lastBounds;
#endregion
- new UIScrollView Control
- {
- get
- {
- Initialize();
- return base.Control;
- }
- }
ICarouselViewController Controller
{
get { return Element; }
@@ -76,6 +69,7 @@ namespace Xamarin.Forms.Platform.iOS
if (carouselView != null)
return;
+ _lastBounds = Bounds;
_controller = new CarouselViewController(
renderer: this,
initialPosition: Element.Position
@@ -141,7 +135,7 @@ namespace Xamarin.Forms.Platform.iOS
break;
case NotifyCollectionChangedAction.Remove:
- if (Element.Count == 0)
+ if (Controller.Count == 0)
throw new InvalidOperationException("CarouselView must retain a least one item.");
if (e.OldStartingIndex == _position)
@@ -149,7 +143,7 @@ namespace Xamarin.Forms.Platform.iOS
_controller.DeleteItems(
Enumerable.Range(e.OldStartingIndex, e.OldItems.Count)
);
- if (_position == Element.Count)
+ if (_position == Controller.Count)
_position--;
OnItemChange(_position);
}
@@ -220,6 +214,17 @@ namespace Xamarin.Forms.Platform.iOS
}
}
+ public override void LayoutSubviews()
+ {
+ base.LayoutSubviews();
+
+ if (_lastBounds == Bounds)
+ return;
+
+ base.Control.ReloadData();
+ _lastBounds = Bounds;
+ _controller.ScrollToPosition(_position, false);
+ }
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
return Control.GetSizeRequest(widthConstraint, heightConstraint, DefaultMinimumDimension, DefaultMinimumDimension);
@@ -352,7 +357,7 @@ namespace Xamarin.Forms.Platform.iOS
}
public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
- var result = Element.Count;
+ var result = Controller.Count;
return result;
}
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/IItemViewController.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/IItemViewController.xml
index 03a410f2..31b59da3 100644
--- a/docs/Xamarin.Forms.Core/Xamarin.Forms/IItemViewController.xml
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/IItemViewController.xml
@@ -32,6 +32,22 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
+ <Member MemberName="Count">
+ <MemberSignature Language="C#" Value="public int Count { get; }" />
+ <MemberSignature Language="ILAsm" Value=".property instance int32 Count" />
+ <MemberType>Property</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <Docs>
+ <summary>To be added.</summary>
+ <value>To be added.</value>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="CreateView">
<MemberSignature Language="C#" Value="public Xamarin.Forms.View CreateView (object itemType);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance class Xamarin.Forms.View CreateView(object itemType) cil managed" />
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/ItemsView.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/ItemsView.xml
index 6f8d1ca5..19c44e77 100644
--- a/docs/Xamarin.Forms.Core/Xamarin.Forms/ItemsView.xml
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/ItemsView.xml
@@ -18,22 +18,6 @@
<remarks>To be added.</remarks>
</Docs>
<Members>
- <Member MemberName="Count">
- <MemberSignature Language="C#" Value="public int Count { get; }" />
- <MemberSignature Language="ILAsm" Value=".property instance int32 Count" />
- <MemberType>Property</MemberType>
- <AssemblyInfo>
- <AssemblyVersion>2.0.0.0</AssemblyVersion>
- </AssemblyInfo>
- <ReturnValue>
- <ReturnType>System.Int32</ReturnType>
- </ReturnValue>
- <Docs>
- <summary>To be added.</summary>
- <value>To be added.</value>
- <remarks>To be added.</remarks>
- </Docs>
- </Member>
<Member MemberName="ItemsSource">
<MemberSignature Language="C#" Value="public System.Collections.IEnumerable ItemsSource { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.IEnumerable ItemsSource" />
@@ -142,6 +126,22 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
+ <Member MemberName="Xamarin.Forms.IItemViewController.Count">
+ <MemberSignature Language="C#" Value="int Xamarin.Forms.IItemViewController.Count { get; }" />
+ <MemberSignature Language="ILAsm" Value=".property instance int32 Xamarin.Forms.IItemViewController.Count" />
+ <MemberType>Property</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <Docs>
+ <summary>To be added.</summary>
+ <value>To be added.</value>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="Xamarin.Forms.IItemViewController.CreateView">
<MemberSignature Language="C#" Value="Xamarin.Forms.View IItemViewController.CreateView (object type);" />
<MemberSignature Language="ILAsm" Value=".method hidebysig newslot virtual instance class Xamarin.Forms.View Xamarin.Forms.IItemViewController.CreateView(object type) cil managed" />