Skip to content

Commit

Permalink
reworked crud operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Dobrynin committed Jul 23, 2024
1 parent 71e235a commit 68613e3
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

using AndroidX.Core.Widget;

using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

namespace MPowerKit.VirtualizeListView;

public partial class VirtualizeListViewHandler
public partial class VirtualizeListViewHandler : ScrollViewHandler
{
protected override MauiScrollView CreatePlatformView()
{
Expand Down
5 changes: 4 additions & 1 deletion MPowerKit.VirtualizeListView/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ public static MauiAppBuilder UseMPowerKitListView(this MauiAppBuilder builder)
{
builder.ConfigureMauiHandlers(handlers =>
{
#if !WINDOWS
#if ANDROID
handlers.AddHandler<VirtualizeListView, VirtualizeListViewHandler>();
#endif
#if !WINDOWS
handlers.AddHandler<FixedRefreshView, FixedRefreshViewRenderer>();
#endif
});
Expand Down
35 changes: 6 additions & 29 deletions MPowerKit.VirtualizeListView/ItemsLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public ItemsLayoutManager(VirtualizeItemsLayoutManger virtualizeItemsLayout) : b

public override Size Measure(double widthConstraint, double heightConstraint)
{
var measuredHeight = 0d;
var measuredWidth = 0d;

Size newSize = new();
if (Layout.ReadOnlyLaidOutItems.Count > 0)
{
Expand All @@ -34,24 +31,12 @@ public override Size Measure(double widthConstraint, double heightConstraint)
var child = items[n];
var view = child as CellHolder;

if (/*view.Item!.IsCached ||*/ view.IsCached || !view.Item.IsAttached) continue;

//var bounds = view.Item.CellBounds;
if (view.IsCached || !view.Item.IsAttached) continue;

// this triggers item size change when needed
var measure = child.Measure(double.PositiveInfinity, double.PositiveInfinity);

//measuredWidth = Math.Max(measuredWidth, bounds.Left + view.Item.Margin.Right + measure.Width);
//measuredHeight = Math.Max(measuredHeight, bounds.Top + view.Item.Margin.Bottom + measure.Height);
}

//var finalWidth = GetFinalLength(Layout.Width, widthConstraint, measuredWidth);
//var finalHeight = GetFinalLength(Layout.Height, heightConstraint, measuredHeight);

//var finalWidth = GetFinalLength(newSize.Width, widthConstraint, measuredWidth);
//var finalHeight = GetFinalLength(newSize.Height, heightConstraint, measuredHeight);

//return new(finalWidth, finalHeight);

return newSize;
}

Expand All @@ -69,10 +54,9 @@ public override Size ArrangeChildren(Rect bounds)
{
var child = items[n];
var view = child as CellHolder;
#if WINDOWS
if (/*view.Item.IsCached ||*/ view.IsCached || !view.Item.IsAttached) continue;
#elif ANDROID
if (/*!view.Item.IsCached &&*/ view.IsCached || !view.Item.IsAttached) continue;

#if !MACIOS
if (view.IsCached || !view.Item.IsAttached) continue;
#endif

var (x, y) =
Expand All @@ -84,7 +68,7 @@ public override Size ArrangeChildren(Rect bounds)

var newBounds = new Rect(x, y, view.DesiredSize.Width, view.DesiredSize.Height);

#if !WINDOWS
#if MACIOS
if (view.Bounds == newBounds) continue;
#endif

Expand All @@ -93,11 +77,4 @@ public override Size ArrangeChildren(Rect bounds)

return new(availableWidth, availableHeight);
}

private double GetFinalLength(double explicitLength, double externalConstraint, double measuredLength)
{
var length = Math.Min(double.IsNaN(explicitLength) ? measuredLength : explicitLength, externalConstraint);

return Math.Max(length, 0);
}
}
8 changes: 4 additions & 4 deletions MPowerKit.VirtualizeListView/LinearItemsLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ protected override void ShiftItemsConsecutively(IReadOnlyList<VirtualizeListView
}
}

protected override bool AdjustScrollIfNeeded(IReadOnlyList<VirtualizeListViewItem> items, VirtualizeListViewItem prevFirstVisiblItem, Rect prevCellBounds)
protected override bool AdjustScrollIfNeeded(IReadOnlyList<VirtualizeListViewItem> items, VirtualizeListViewItem prevItem, Rect prevCellBounds)
{
if (IsOrientation(ScrollOrientation.Both) || prevFirstVisiblItem.Position == -1) return false;
if (IsOrientation(ScrollOrientation.Both) || prevItem.Position == -1) return false;

bool needs;

if (IsOrientation(ScrollOrientation.Vertical))
{
var dy = prevFirstVisiblItem.CellBounds.Bottom - prevCellBounds.Bottom;
var dy = prevItem.CellBounds.Bottom - prevCellBounds.Bottom;

needs = dy != 0d;
if (!needs) return needs;
Expand All @@ -197,7 +197,7 @@ protected override bool AdjustScrollIfNeeded(IReadOnlyList<VirtualizeListViewIte
}
else
{
var dx = prevFirstVisiblItem.CellBounds.Right - prevCellBounds.Right;
var dx = prevItem.CellBounds.Right - prevCellBounds.Right;

needs = dx != 0d;
if (!needs) return needs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>

<DefineConstants Condition="$(TargetFramework.Contains('ios')) OR $(TargetFramework.Contains('maccatalyst'))">$(DefineConstants);MACIOS</DefineConstants>

<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MPowerKit.VirtualizeListView</Title>
<Version>1.1.7</Version>
<Version>1.2.0</Version>
<Authors>MPowerKit,Alex Dobrynin</Authors>
<Description>MAUI Virtualize ListView with smooth scrolling and without platform-specific code</Description>
<Copyright>MPowerKit</Copyright>
Expand Down
16 changes: 0 additions & 16 deletions MPowerKit.VirtualizeListView/MaciOS/VirtualizeListViewHandler.cs

This file was deleted.

Loading

0 comments on commit 68613e3

Please sign in to comment.