This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#4406 * [Android] ItemContentView should use all available space; fixes #4406 Fix inconsistent/inaccurate class naming for cells/views. * Update Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentView.cs Add missing space. Co-Authored-By: hartez <hartez@users.noreply.github.com> * Make ReuseId values match class names
- Loading branch information
Showing
15 changed files
with
121 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
Xamarin.Forms.Platform.Android/CollectionView/ItemContentControl.cs
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
Xamarin.Forms.Platform.Android/CollectionView/ItemContentView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Android.Content; | ||
using Android.Views; | ||
|
||
namespace Xamarin.Forms.Platform.Android | ||
{ | ||
internal class ItemContentView : ViewGroup | ||
{ | ||
protected readonly IVisualElementRenderer Content; | ||
|
||
public ItemContentView(IVisualElementRenderer content, Context context) : base(context) | ||
{ | ||
Content = content; | ||
AddContent(); | ||
} | ||
|
||
void AddContent() | ||
{ | ||
AddView(Content.View); | ||
} | ||
|
||
protected override void OnLayout(bool changed, int l, int t, int r, int b) | ||
{ | ||
var size = Context.FromPixels(r - l, b - t); | ||
|
||
Content.Element.Layout(new Rectangle(Point.Zero, size)); | ||
|
||
Content.UpdateLayout(); | ||
} | ||
|
||
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) | ||
{ | ||
int pixelWidth = MeasureSpec.GetSize(widthMeasureSpec); | ||
int pixelHeight = MeasureSpec.GetSize(heightMeasureSpec); | ||
|
||
var width = Context.FromPixels(pixelWidth); | ||
var height = Context.FromPixels(pixelHeight); | ||
|
||
SizeRequest measure = Content.Element.Measure(width, height, MeasureFlags.IncludeMargins); | ||
|
||
if (pixelWidth == 0) | ||
{ | ||
pixelWidth = (int)Context.ToPixels(Content.Element.Width > 0 | ||
? Content.Element.Width | ||
: measure.Request.Width); | ||
} | ||
|
||
if (pixelHeight == 0) | ||
{ | ||
pixelHeight = (int)Context.ToPixels(Content.Element.Height > 0 | ||
? Content.Element.Height | ||
: measure.Request.Height); | ||
} | ||
|
||
SetMeasuredDimension(pixelWidth, pixelHeight); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentControl.cs
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
Xamarin.Forms.Platform.Android/CollectionView/SizedItemContentView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using Android.Content; | ||
|
||
namespace Xamarin.Forms.Platform.Android | ||
{ | ||
internal class SizedItemContentView : ItemContentView | ||
{ | ||
readonly Func<int> _width; | ||
readonly Func<int> _height; | ||
|
||
public SizedItemContentView(IVisualElementRenderer content, Context context, Func<int> width, Func<int> height) | ||
: base(content, context) | ||
{ | ||
_width = width; | ||
_height = height; | ||
} | ||
|
||
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) | ||
{ | ||
var targetWidth = _width(); | ||
var targetHeight = _height(); | ||
|
||
Content.Element.Measure(Context.FromPixels(targetWidth), Context.FromPixels(targetHeight), | ||
MeasureFlags.IncludeMargins); | ||
|
||
SetMeasuredDimension(targetWidth, targetHeight); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters