Skip to content

Commit eacb4a0

Browse files
committed
feat: NeedsFrame porperty for SampleAttribute
1 parent 913da44 commit eacb4a0

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Presentation/SampleChooserViewModel.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#if HAS_UNO
2424
using Uno.Foundation.Logging;
25+
using MUXControlsTestApp;
2526
#else
2627
using Microsoft.Extensions.Logging;
2728
using Uno.Logging;
@@ -689,7 +690,8 @@ SampleChooserContent GetContent(TypeInfo type, SampleAttribute attribute)
689690
Description = attribute.Description,
690691
ControlType = type.AsType(),
691692
IgnoreInSnapshotTests = attribute.IgnoreInSnapshotTests,
692-
IsManualTest = attribute.IsManualTest
693+
IsManualTest = attribute.IsManualTest,
694+
UsesFrame = attribute.UsesFrame
693695
};
694696
}
695697

@@ -847,7 +849,6 @@ private async Task<List<SampleChooserContent>> GetFavoriteSamples(CancellationTo
847849
}
848850
}
849851

850-
851852
/// <summary>
852853
/// This method receives a newContent and returns a newly built content. It also adds the content to the settings for the latest ran tests.
853854
/// </summary>
@@ -859,10 +860,12 @@ public async Task<object> UpdateContent(CancellationToken ct, SampleChooserConte
859860
SampleChanging?.Invoke(this, EventArgs.Empty);
860861

861862
FrameworkElement container = null;
862-
if (typeof(Page).IsAssignableFrom(newContent.ControlType))
863-
{
864-
// Content is a page, for MUX compatibility we use Frame to navigate to it.
865-
// This ensures the Page.Frame property is not null.
863+
864+
var frameRequested =
865+
newContent.UsesFrame &&
866+
typeof(Page).IsAssignableFrom(newContent.ControlType);
867+
if (frameRequested)
868+
{
866869
var frame = new Frame();
867870
frame.Navigate(newContent.ControlType);
868871
container = frame;

src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleChooserContent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public partial class SampleChooserContent : INotifyPropertyChanged
1818
public string Description { get; set; }
1919
public bool IgnoreInSnapshotTests { get; internal set; }
2020
public bool IsManualTest { get; internal set; }
21+
public bool UsesFrame { get; internal set; }
2122

2223
bool _isFavorite;
2324
public bool IsFavorite

src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Controls/SampleControlInfoAttribute.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public SampleControlInfoAttribute(
1515
Type viewModelType = null,
1616
bool ignoreInSnapshotTests = false,
1717
string description = null,
18-
bool isManualTest = false
18+
bool isManualTest = false,
19+
bool usesFrame = true
1920
)
2021
: base(category)
2122
{
@@ -24,6 +25,7 @@ public SampleControlInfoAttribute(
2425
IgnoreInSnapshotTests = ignoreInSnapshotTests;
2526
IsManualTest = isManualTest;
2627
Description = description;
28+
UsesFrame = usesFrame;
2729
}
2830

2931
}
@@ -89,5 +91,11 @@ public SampleAttribute(params Type[] categories)
8991
/// An optional description of the sample. A good practice is to explain the expected result of the sample.
9092
/// </summary>
9193
public string Description { get; set; }
94+
95+
/// <summary>
96+
/// Set to true if the sample is navigated to using frame navigation.
97+
/// </summary>
98+
/// <remarks>Defaults to true.</remarks>
99+
public bool UsesFrame { get; set; } = true;
92100
}
93101
}

0 commit comments

Comments
 (0)