Skip to content

Commit

Permalink
Add needsview to windows for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Nov 28, 2023
1 parent 79d7ff5 commit bbf31a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
36 changes: 15 additions & 21 deletions VirtualListView/Platforms/Windows/IrElementContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,27 @@ internal bool IsRecycled
}
}

public bool NeedsView
=> VirtualView is null || VirtualView.Handler is null;

public IView VirtualView { get; private set; }

public void Update(PositionInfo positionInfo, IView newView)
public void SetupView(IView view)
{
PositionInfo = positionInfo;

if (newView is IPositionInfo viewWithPositionInfo)
viewWithPositionInfo.Update(PositionInfo);

SwapView(newView);
if (VirtualView is null || VirtualView.Handler is null)
{
Content = view.ToPlatform(MauiContext);
VirtualView = view;
}
}

void SwapView(IView newView)
public void UpdatePosition(PositionInfo positionInfo)
{
if (VirtualView == null || VirtualView.Handler == null || Content == null)
{
Content = newView.ToPlatform(MauiContext);
VirtualView = newView;
}
else
{
var handler = VirtualView.Handler;
newView.Handler = handler;
handler.SetVirtualView(newView);
VirtualView = newView;
}
}
PositionInfo = positionInfo;

if (VirtualView is IPositionInfo viewWithPositionInfo)
viewWithPositionInfo.Update(PositionInfo);
}

protected override void OnTapped(TappedRoutedEventArgs e)
{
Expand Down
15 changes: 8 additions & 7 deletions VirtualListView/Platforms/Windows/IrElementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ public UIElement GetElement(UI.Xaml.ElementFactoryGetArgs args)
&& (Handler?.IsItemSelected(info.SectionIndex, info.ItemIndex) ?? false);


var view = container.VirtualView ?? PositionalViewSelector.ViewSelector?.CreateView(info, data);

container.Update(info, view);


if (container.NeedsView)
{
var virtualView = PositionalViewSelector.ViewSelector?.CreateView(info, data);
container.SetupView(virtualView);
}

container.UpdatePosition(info);
container.IsRecycled = false;
PositionalViewSelector.ViewSelector?.RecycleView(info, data, view);

PositionalViewSelector.ViewSelector?.ViewAttached(info, view);
PositionalViewSelector.ViewSelector?.RecycleView(info, data, container.VirtualView);
PositionalViewSelector.ViewSelector?.ViewAttached(info, container.VirtualView);

return container;
}
Expand Down

0 comments on commit bbf31a3

Please sign in to comment.