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

Commit

Permalink
Use Xamarin.Forms.Size instead of Android.Util.Size to work with API …
Browse files Browse the repository at this point in the history
…< 21 (#7033) fixes #6815

Fixes #6815
  • Loading branch information
hartez authored and rmarinho committed Aug 1, 2019
1 parent 912fbcc commit 1d362ad
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.ScrollModeGalleries;
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.AlternateLayoutGalleries;
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.HeaderFooterGalleries;
using Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries.ItemSizeGalleries;

namespace Xamarin.Forms.Controls.GalleryPages.CollectionViewGalleries
{
Expand All @@ -26,6 +27,7 @@ public CollectionViewGallery()
GalleryBuilder.NavButton("Selection Galleries", () => new SelectionGallery(), Navigation),
GalleryBuilder.NavButton("Propagation Galleries", () => new PropagationGallery(), Navigation),
GalleryBuilder.NavButton("Grouping Galleries", () => new GroupingGallery(), Navigation),
GalleryBuilder.NavButton("Item Size Galleries", () => new ItemsSizeGallery(), Navigation),
GalleryBuilder.NavButton("Scroll Mode Galleries", () => new ScrollModeGallery(), Navigation),
GalleryBuilder.NavButton("Alternate Layout Galleries", () => new AlternateLayoutGallery(), Navigation),
GalleryBuilder.NavButton("Header/Footer Galleries", () => new HeaderFooterGallery(), Navigation),
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Controls/GalleryPages/GalleryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class GalleryBuilder
public static Button NavButton(string galleryName, Func<ContentPage> gallery, INavigation nav)
{
var automationId = System.Text.RegularExpressions.Regex.Replace(galleryName, " |\\(|\\)", string.Empty);
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = 40 };
var button = new Button { Text = $"{galleryName}", AutomationId = automationId, FontSize = 10, HeightRequest = 30 };
button.Clicked += (sender, args) => { nav.PushAsync(gallery()); };
return button;
}
Expand Down
11 changes: 5 additions & 6 deletions Xamarin.Forms.Platform.Android/CollectionView/ItemContentView.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;
using Android.Content;
using Android.Views;
using ASize = Android.Util.Size;

namespace Xamarin.Forms.Platform.Android
{
internal class ItemContentView : ViewGroup
{
protected IVisualElementRenderer Content;
ASize _size;
Action<ASize> _reportMeasure;
Size? _size;
Action<Size> _reportMeasure;

public ItemContentView(Context context) : base(context)
{
Expand Down Expand Up @@ -43,7 +42,7 @@ internal void Recycle()
_size = null;
}

internal void HandleItemSizingStrategy(Action<ASize> reportMeasure, ASize size)
internal void HandleItemSizingStrategy(Action<Size> reportMeasure, Size? size)
{
_reportMeasure = reportMeasure;
_size = size;
Expand Down Expand Up @@ -74,7 +73,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
if (_size != null)
{
// If we're using ItemSizingStrategy.MeasureFirstItem and now we have a set size, use that
SetMeasuredDimension(_size.Width, _size.Height);
SetMeasuredDimension((int)_size.Value.Width, (int)_size.Value.Height);
return;
}

Expand All @@ -101,7 +100,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
pixelHeight = (int)Context.ToPixels(measure.Request.Height);
}

_reportMeasure?.Invoke(new ASize(pixelWidth, pixelHeight));
_reportMeasure?.Invoke(new Size(pixelWidth, pixelHeight));
_reportMeasure = null; // Make sure we only report back the measure once

SetMeasuredDimension(pixelWidth, pixelHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Android.Widget;
using Object = Java.Lang.Object;
using ViewGroup = Android.Views.ViewGroup;
using ASize = Android.Util.Size;

namespace Xamarin.Forms.Platform.Android
{
Expand All @@ -15,7 +14,7 @@ public class ItemsViewAdapter : RecyclerView.Adapter
internal readonly IItemsViewSource ItemsSource;

bool _disposed;
ASize _size;
Size? _size;

bool _usingItemTemplate = false;
int _headerOffset = 0;
Expand Down Expand Up @@ -119,7 +118,7 @@ void BindTemplatedItemViewHolder(TemplatedItemViewHolder templatedItemViewHolder
}
}

void SetStaticSize(ASize size)
void SetStaticSize(Size size)
{
_size = size;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Xamarin.Forms.Internals;
using ASize = Android.Util.Size;

namespace Xamarin.Forms.Platform.Android
{
Expand Down Expand Up @@ -39,7 +38,7 @@ public void Recycle(ItemsView itemsView)
}

public void Bind(object itemBindingContext, ItemsView itemsView,
Action<ASize> reportMeasure = null, ASize size = null)
Action<Size> reportMeasure = null, Size? size = null)
{
var template = _template.SelectDataTemplate(itemBindingContext, itemsView);

Expand Down

0 comments on commit 1d362ad

Please sign in to comment.