-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into theming-feature
- Loading branch information
Showing
26 changed files
with
1,189 additions
and
76 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MauiReactor.TestApp.Pages; | ||
|
||
class PickerPageState | ||
{ | ||
public DateTime TimeStamp { get; set; } = DateTime.Now; | ||
} | ||
|
||
class PickerPage : Component<PickerPageState> | ||
{ | ||
public override VisualNode Render() | ||
{ | ||
return ContentPage("Pickers Page", | ||
VStack(spacing: 10, | ||
DatePicker() | ||
.Date(State.TimeStamp) | ||
.OnDateSelected(newDate => SetState(s => s.TimeStamp = new DateTime(DateOnly.FromDateTime(newDate), TimeOnly.FromDateTime(s.TimeStamp)))), | ||
|
||
TimePicker() | ||
.Time(State.TimeStamp.TimeOfDay) | ||
.OnTimeSelected(newTime => SetState(s => s.TimeStamp = new DateTime(DateOnly.FromDateTime(s.TimeStamp), TimeOnly.FromTimeSpan(newTime)))) | ||
|
||
) | ||
.Center() | ||
); | ||
} | ||
} |
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,48 @@ | ||
using MauiReactor.TestApp.Services; | ||
using Microsoft.Maui; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MauiReactor.TestApp.Pages; | ||
|
||
[Component("BaseComponent2_1")] | ||
abstract partial class BaseComponent2<TState> : Component<TState> where TState : class, new() | ||
{ | ||
[Inject] protected readonly IncrementService? _injectedService; | ||
[Prop] protected MauiControls.Shell? shellRef; | ||
} | ||
|
||
[Component("BaseComponent2_2")] | ||
abstract partial class BaseComponent2<TState, TProps> : Component<TState, TProps> where TState : class, new() | ||
where TProps : class, new() | ||
{ | ||
[Inject] protected readonly IncrementService? _injectedService; | ||
[Prop] protected MauiControls.Shell? shellRef; | ||
} | ||
|
||
class TestBug218_1 : BaseComponent2<TestBug218_1.MyState> | ||
{ | ||
public class MyState | ||
{ } | ||
|
||
public override VisualNode Render() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
class TestBug218_2 : BaseComponent2<TestBug218_2.MyState, TestBug218_2.MyProps> | ||
{ | ||
public class MyState | ||
{ } | ||
public class MyProps | ||
{ } | ||
|
||
public override VisualNode Render() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
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,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MauiReactor.TestApp.Pages; | ||
|
||
public class TestBug220ShellPage : Component | ||
{ | ||
private MauiControls.Shell? shell; | ||
|
||
/// <inheritdoc /> | ||
public override VisualNode Render() => | ||
new Shell(x => shell = x!) | ||
{ | ||
new ShellContent("Models") | ||
.AutomationId("Models") | ||
//.Icon(FontImages.Feature) | ||
.RenderContent(() => new ListPage().Shell(shell)) | ||
} | ||
.AutomationId("MainShell"); | ||
} | ||
|
||
public record Model(string Id, string Name); | ||
|
||
public partial class ListPage : Component<ListPage.PageState> | ||
{ | ||
[Prop("Shell")] protected MauiControls.Shell? shellRef; | ||
|
||
public override VisualNode Render() => | ||
new ContentPage | ||
{ | ||
new CollectionView() | ||
.AutomationId("list") | ||
.ItemsSource(State.Items, Render) | ||
} | ||
.AutomationId("Models_page"); | ||
|
||
protected override void OnMounted() | ||
{ | ||
Routing.RegisterRoute<TestBug220ModelPage>("model"); | ||
|
||
Task.Run( | ||
async () => | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(2)); | ||
SetState(s => s.Items = new[] { new Model("m1", "model name 1") }); | ||
}); | ||
base.OnMounted(); | ||
} | ||
|
||
private VisualNode Render(Model item) => | ||
new VStack(5) | ||
{ | ||
new Label(item.Name).AutomationId(item.Id + "-name"), | ||
new Label(item.Id).AutomationId(item.Id + "-id") | ||
.FontSize(12) | ||
.TextColor(Colors.Gray) | ||
}.AutomationId(item.Id + "-stack") | ||
.OnTapped( | ||
async () => await shellRef!.GoToAsync<TestBug220ModelPage.Props2>( | ||
"model", | ||
props => props.Id = item.Id)) | ||
.Margin(5, 10); | ||
|
||
public class PageState | ||
{ | ||
public Model[] Items { get; set; } = | ||
[ | ||
]; | ||
} | ||
} | ||
|
||
public class TestBug220ModelPage : Component<TestBug220ModelPage.PageState, TestBug220ModelPage.Props2> | ||
{ | ||
public override VisualNode Render() => | ||
new ContentPage("Model") | ||
{ | ||
new Label(State.Item?.Name) | ||
.AutomationId(State.Item?.Id ?? string.Empty) | ||
.VCenter() | ||
.HCenter() | ||
}; | ||
|
||
protected override void OnMountedOrPropsChanged() | ||
{ | ||
Task.Run( | ||
async () => | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(2)); | ||
SetState(s => s.Item = new Model("m2", "model name 2")); | ||
}); | ||
|
||
base.OnMounted(); | ||
} | ||
|
||
public class PageState | ||
{ | ||
public Model? Item { get; set; } | ||
} | ||
|
||
public class Props2 | ||
{ | ||
public string Id { get; set; } = null!; | ||
} | ||
} |
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,59 @@ | ||
using MauiReactor; | ||
using MauiReactor.Internals; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shouldly; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MauiReactor.TestApp.Pages; | ||
using System.Reflection; | ||
|
||
namespace UnitTests; | ||
|
||
internal class TestBug220Page | ||
{ | ||
[Test] | ||
public async Task VerifyLabelOnModelPage() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
using var serviceContext = new ServiceContext(provider); | ||
|
||
var mainPage = TemplateHost.Create(new TestBug220ShellPage()); | ||
var shell = mainPage.Find<MauiControls.Shell>("MainShell"); | ||
var models = shell.Find<MauiControls.ShellContent>("Models"); | ||
var modelsPage = mainPage.Find<MauiControls.ContentPage>("Models_page"); | ||
|
||
shell.CurrentItem = models; | ||
|
||
// first way | ||
var name = await mainPage.Find<MauiControls.Label>("m1-name", TimeSpan.FromSeconds(30)); | ||
|
||
name.ShouldNotBeNull(); | ||
name.Text.ShouldBe("model name 1"); | ||
|
||
// get and click on item in collection view | ||
var stack = await mainPage.Find<MauiControls.VerticalStackLayout>("m1-stack", TimeSpan.FromSeconds(30)); | ||
|
||
stack.ShouldNotBeNull(); | ||
|
||
// how to tap the stack?? | ||
var tapGestureRecognizer = stack.GestureRecognizers.OfType<MauiControls.TapGestureRecognizer>().Single(); | ||
|
||
tapGestureRecognizer | ||
.GetType() | ||
.GetMethod("SendTapped", BindingFlags.Instance | BindingFlags.NonPublic) | ||
.ShouldNotBeNull().Invoke(tapGestureRecognizer, new[] { stack, null }); | ||
|
||
// get ModelPage and get the label | ||
var label = await mainPage.Find<MauiControls.Label>("m2", TimeSpan.FromSeconds(30)); | ||
|
||
label.ShouldNotBeNull(); | ||
|
||
// test the label of ModelPage | ||
label.Text.ShouldBe("model name 2"); | ||
} | ||
} |
Oops, something went wrong.