-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back some aspect of ConvertView on TableView and avoid AT_MOST …
…Measure (#20130) * Bring back some aspect of convertView on TableView * Update TableViewRenderer.cs * - add more tests * - add comments fix double create of views * - add extra disconnect code to GetCell * - fix events
- Loading branch information
Showing
16 changed files
with
404 additions
and
56 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
123 changes: 123 additions & 0 deletions
123
src/Controls/samples/Controls.Sample.UITests/Issues/Issue5555.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,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.None, 5555, "Memory leak when SwitchCell or EntryCell", PlatformAffected.iOS)] | ||
public class Issue5555 : TestContentPage | ||
{ | ||
public static Label DestructorCount = new Label() { Text = "0" }; | ||
protected override void Init() | ||
{ | ||
var instructions = new Label | ||
{ | ||
FontSize = 16, | ||
Text = "Click 'Push page' twice" | ||
}; | ||
|
||
var result = new Label | ||
{ | ||
Text = "Success", | ||
AutomationId = "SuccessLabel", | ||
IsVisible = false | ||
}; | ||
|
||
var list = new List<WeakReference>(); | ||
|
||
var checkButton = new Button | ||
{ | ||
Text = "Check Result", | ||
AutomationId = "CheckResult", | ||
IsVisible = false, | ||
Command = new Command(async () => | ||
{ | ||
if (list.Count < 2) | ||
{ | ||
instructions.Text = "Click 'Push page' again"; | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
await GarbageCollectionHelper.WaitForGC(2500, list.ToArray()); | ||
result.Text = "Success"; | ||
result.IsVisible = true; | ||
instructions.Text = ""; | ||
} | ||
catch (Exception) | ||
{ | ||
instructions.Text = "Failed"; | ||
result.IsVisible = false; | ||
return; | ||
} | ||
}) | ||
}; | ||
|
||
Content = new StackLayout | ||
{ | ||
Children = { | ||
DestructorCount, | ||
instructions, | ||
result, | ||
new Button | ||
{ | ||
Text = "Push page", | ||
AutomationId = "PushPage", | ||
Command = new Command(async() => { | ||
if (list.Count >= 2) | ||
list.Clear(); | ||
|
||
var wref = new WeakReference(new LeakPage()); | ||
|
||
await Navigation.PushAsync(wref.Target as Page); | ||
await (wref.Target as Page).Navigation.PopAsync(); | ||
|
||
list.Add(wref); | ||
if (list.Count > 1) | ||
{ | ||
checkButton.IsVisible = true; | ||
instructions.Text = "You can check result"; | ||
} | ||
else | ||
{ | ||
instructions.Text = "Again"; | ||
} | ||
}) | ||
}, | ||
checkButton | ||
} | ||
}; | ||
} | ||
|
||
class LeakPage : ContentPage | ||
{ | ||
public LeakPage() | ||
{ | ||
Content = new StackLayout | ||
{ | ||
Children = { | ||
new Entry { Text = "LeakPage" }, | ||
new TableView | ||
{ | ||
Root = new TableRoot | ||
{ | ||
new TableSection | ||
{ | ||
new SwitchCell { Text = "switch cell", On = true }, | ||
new EntryCell { Text = "entry cell" } | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
~LeakPage() | ||
{ | ||
System.Diagnostics.Debug.WriteLine("LeakPage Finalized"); | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Controls/samples/Controls.Sample.UITests/Issues/Issue5924.xaml
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,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue5924" | ||
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues"> | ||
<TableView Intent="Settings"> | ||
<TableRoot> | ||
<TableSection Title="Locations"> | ||
<ViewCell> | ||
<AbsoluteLayout> | ||
<Label AutomationId="label" Text="Enter text into the Entry field and it shouldn't disappear" HorizontalOptions="Start" VerticalOptions="Center" AbsoluteLayout.LayoutBounds="0,0.5" AbsoluteLayout.LayoutFlags="PositionProportional"/> | ||
<Entry AutomationId="entry" HorizontalOptions="End" VerticalOptions="Center" AbsoluteLayout.LayoutBounds="1,0.5" AbsoluteLayout.LayoutFlags="PositionProportional"/> | ||
</AbsoluteLayout> | ||
</ViewCell> | ||
</TableSection> | ||
</TableRoot> | ||
</TableView> | ||
</ContentPage> |
18 changes: 18 additions & 0 deletions
18
src/Controls/samples/Controls.Sample.UITests/Issues/Issue5924.xaml.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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 5924, "TableView ViewCell vanishes after content is updated", PlatformAffected.Android)] | ||
public partial class Issue5924 : ContentPage | ||
{ | ||
public Issue5924() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/Controls/samples/Controls.Sample.UITests/Utils/GarbageCollectionHelper.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,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Maui.Controls.Sample | ||
{ | ||
public static class GarbageCollectionHelper | ||
{ | ||
public static async Task WaitForGC(params WeakReference[] references) => await WaitForGC(5000, references); | ||
|
||
public static async Task WaitForGC(int timeout, params WeakReference[] references) | ||
{ | ||
bool referencesCollected() | ||
{ | ||
GC.Collect(); | ||
GC.WaitForPendingFinalizers(); | ||
|
||
foreach (var reference in references) | ||
{ | ||
if (reference.IsAlive) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
await AssertEventually(referencesCollected, timeout); | ||
} | ||
|
||
public static async Task AssertEventually(this Func<bool> assertion, int timeout = 1000, int interval = 100, string message = "Assertion timed out") | ||
{ | ||
do | ||
{ | ||
if (assertion()) | ||
{ | ||
return; | ||
} | ||
|
||
await Task.Delay(interval); | ||
timeout -= interval; | ||
|
||
} | ||
while (timeout >= 0); | ||
|
||
if (!assertion()) | ||
{ | ||
throw new Exception(message); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.