Skip to content

Commit

Permalink
Merge branch 'main' into theming-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
adospace committed Mar 15, 2024
2 parents 036ac11 + 115f852 commit 85d64c0
Show file tree
Hide file tree
Showing 26 changed files with 1,189 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
Solution_Name: ./src/MauiReactor.Build.sln
TemplatePack_Name: ./src/MauiReactor.TemplatePack/MauiReactor.TemplatePack.csproj
Version: 2.0.27
Version: 2.0.33

steps:
- name: Checkout
Expand Down
11 changes: 9 additions & 2 deletions samples/MauiReactor.MapsDemo/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public override VisualNode Render()
{
new Map()
{
State.Positions.Select((location, index)=> new Pin().Location(location).Label($"Pin{index+1}"))
State.Positions.Select((location, index)=> new Pin()
.Location(location)
.Label($"Pin{index+1}")
.OnMarkerClicked(()=> SetState(s => s.Positions.Remove(location)))
)
}
.AutomationId("Map")
.GridRow(1)
.OnMapClicked((map, args) => SetState(s => s.Positions.Add(args.Location)))
.OnMapClicked((map, args) =>
{
SetState(s => s.Positions.Add(args.Location));
})
};
}
}
5 changes: 5 additions & 0 deletions samples/MauiReactor.TestApp/HomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public override VisualNode Render()
{
new BehaviorTestPage()
},

new FlyoutItem("Pickers Page")
{
new PickerPage()
},
}
.ItemTemplate(RenderItemTemplate);
}
Expand Down
18 changes: 13 additions & 5 deletions samples/MauiReactor.TestApp/Pages/CollectionViewPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ public override VisualNode Render()
}

private VisualNode RenderItem(Tuple<string, string> item)
=> new VStack(spacing: 5)
{
new Label(item.Item1).AutomationId(item.Item1), //AutomationId used for test
new Label(item.Item2)
}.AutomationId($"Container_{item.Item1}");
=> SwipeView(
VStack(spacing: 5,
Label(item.Item1).AutomationId(item.Item1), //AutomationId used for test
Label(item.Item2)
).AutomationId($"Container_{item.Item1}")
)
.RightItems([
SwipeItemView(
HStack(
Label("Custom Swipte Item")
)
)
]);
}
}
32 changes: 32 additions & 0 deletions samples/MauiReactor.TestApp/Pages/PickerPage.cs
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()
);
}
}
48 changes: 48 additions & 0 deletions samples/MauiReactor.TestApp/Pages/TestBug218.cs
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();
}
}
107 changes: 107 additions & 0 deletions samples/MauiReactor.TestApp/Pages/TestBug220.cs
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!;
}
}
59 changes: 59 additions & 0 deletions samples/UnitTests/TestBug220Page.cs
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");
}
}
Loading

0 comments on commit 85d64c0

Please sign in to comment.