From 330a88e3cb293eb88f9569e3ac6384cab09668c8 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Thu, 11 May 2023 12:09:31 -0500 Subject: [PATCH 1/2] Clear out the renderer on VCR when disconnected --- .../Handlers/ListView/iOS/ViewCellRenderer.cs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs index 38971147b2ce..bf3f1d6f2c88 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs @@ -41,6 +41,20 @@ public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, return cell; } + + + +#pragma warning disable RS0016 // Add public types and members to the declared API + protected override void DisconnectHandler(UITableViewCell platformView) +#pragma warning restore RS0016 // Add public types and members to the declared API + { + if (platformView is ViewTableCell vtc) + { + vtc.ViewCell = null; + } + } + + internal class ViewTableCell : UITableViewCell, INativeElementView { IMauiContext MauiContext => _viewCell.FindMauiContext(); @@ -170,7 +184,7 @@ IPlatformViewHandler GetNewRenderer() var newRenderer = _viewCell.View.ToHandler(_viewCell.View.FindMauiContext()); _rendererRef = new WeakReference(newRenderer); - ContentView.AddSubview(newRenderer.PlatformView); + ContentView.AddSubview(newRenderer.VirtualView.ToPlatform()); return (IPlatformViewHandler)newRenderer; } @@ -187,6 +201,14 @@ void UpdateCell(ViewCell cell) } _viewCell = cell; + + if (cell is null) + { + _rendererRef = null; + ContentView.ClearSubviews(); + return; + } + _viewCell.PropertyChanged += ViewCellPropertyChanged; BeginInvokeOnMainThread(_viewCell.SendAppearing); From fe8935b5680cc310f170051a7926dfa14eceaf24 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 15 May 2023 17:21:50 -0500 Subject: [PATCH 2/2] - remove extra disconnect --- .../Handlers/ListView/iOS/CellTableViewCell.cs | 1 - .../Handlers/ListView/iOS/ViewCellRenderer.cs | 15 +-------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs index dd9ce677a549..3ec0d531bc93 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs @@ -72,7 +72,6 @@ internal static UITableViewCell GetPlatformCell(UITableView tableView, Cell cell else reusableCell = tableView.DequeueReusableCell(id); - cell.Handler?.DisconnectHandler(); cell.ReusableCell = reusableCell; cell.TableView = tableView; var handler = cell.ToHandler(cell.FindMauiContext()); diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs index bf3f1d6f2c88..bdafd5a30035 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ViewCellRenderer.cs @@ -41,20 +41,6 @@ public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, return cell; } - - - -#pragma warning disable RS0016 // Add public types and members to the declared API - protected override void DisconnectHandler(UITableViewCell platformView) -#pragma warning restore RS0016 // Add public types and members to the declared API - { - if (platformView is ViewTableCell vtc) - { - vtc.ViewCell = null; - } - } - - internal class ViewTableCell : UITableViewCell, INativeElementView { IMauiContext MauiContext => _viewCell.FindMauiContext(); @@ -184,6 +170,7 @@ IPlatformViewHandler GetNewRenderer() var newRenderer = _viewCell.View.ToHandler(_viewCell.View.FindMauiContext()); _rendererRef = new WeakReference(newRenderer); + ContentView.ClearSubviews(); ContentView.AddSubview(newRenderer.VirtualView.ToPlatform()); return (IPlatformViewHandler)newRenderer; }