adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
555 stars 46 forks source link

.NET 8 #166

Closed adospace closed 5 months ago

adospace commented 8 months ago

Hey guys,

I'm really happy to let you know that the journey to .NET 8 has officially started for MauiReactor too.

It was a fantastic year for MauiReactor, with more than 400 stars and 30 daily unique visitors I can safely say that is no more a niche library in the .NET MAUI universe and this is all thanks to your continued support.

If you are working on your next great app using MauiReactor, you're in my company! :) I personally use MauiReactor for apps I build for my clients and I'm highly involved in maintaining the library in the future.

Today I've ported MauiReactor to .NET 8 RC2 in literally 5 minutes, just retargeting and referencing the MAUI Nuget packages!

Please check it out and see how it works for you: https://github.com/adospace/reactorui-maui/tree/net-8-rc2

MauiReactor unique daily visitors: image

juanyacovino77 commented 8 months ago

Ado, we really appreciate your work!

Reactor it is a fantastic UI library!

Code-DJ commented 8 months ago

Hi @adospace is .net 8.0 working fine for you?

I upgraded my working .net 7.0 project to .net 8.0 by making the following changes:

When I build and run the solution, the app launches in iOS Simulator but when I click on a button the event doesn't fire. This works fine on .net 7.0.

Thanks!

adospace commented 7 months ago

.NET 8 beta release available on Nuget: https://www.nuget.org/packages/Reactor.Maui pick the latest 2.0.*-beta version, enjoy!

Code-DJ commented 7 months ago

.NET 8 beta release available on Nuget: nuget.org/packages/Reactor.Maui pick the latest 2.0.*-beta version, enjoy!

Hi @adospace the version is hardcoded in the yml to 2.0.3-beta so I think it got a conflict since it already exists in nuget.org. Also there is a typo TemokatePack_Name.

rzmz commented 7 months ago

I started weeping of joy when I discovered this beta release works with .NET 8 and with hot reload! You sir are doing good work.

bub-bl commented 6 months ago

.NET 8 HotReload not working on my side

adospace commented 6 months ago

The latest build version 2.0.7-beta introduces a new way to declare components.

Instead of writing code like this:

public override VisualNode Render()
{
    return new ContentPage("Counter Sample")
    {
        new VStack(spacing: 10)
        {
            new Label($"Counter: {State.Counter}")
                .VCenter()
                .HCenter(),

            new Button("Click To Increment", () =>
                SetState(s => s.Counter++))
        }
        .VCenter()
        .HCenter()
    };
}

you can now write code like this:

public override VisualNode Render()
      => ContentPage("Counter Sample",
      [
          VStack(
          [
              Label($"Counter: {State.Counter}"),

              Button("Click To Increment", () =>
                  SetState(s => s.Counter++))
          ])
          .Spacing(10)
          .Center()
      ]);

In the sample above ContentPage, VStack, Label, and Button objects are reused (pooled) when the state changes (i.e. when you call SetState). Even if those objects are just wrappers around native controls (the heavy things), they would still be created as new instances every time the Render method executes, causing some pressure on the GC.

The effect of object pooling is more evident when you need to render items of collections as shown below:

public override VisualNode Render()
{
    return new ContentPage("CollectionView")
    {
        new CollectionView()
            .ItemsSource(ItemsSource, RenderItem)
    };
}

private VisualNode RenderItem(MyItem item)
    => new VStack(spacing: 5)
    {
        new Label(item.Item1),
        new Label(item.Item2)
    };
VisualNode RenderItem(MyItem item)
    => VStack(
    [
        Label(item.Item1),
        Label(item.Item2)
    ])
    .Spacing(5);

You can choose one format or the other, and generally, there isn't a recommended one. The new pattern (pooled) can provide benefits in contests like render collection view items.

Code-DJ commented 6 months ago

@adospace I guess the new pooling methods won't work if you need access to the componentRefAction right? Same is true for ListView that needs ListViewCachingStrategy.RecycleElementAndDataTemplate. Am I missing something? Thanks!

adospace commented 6 months ago

@Code-DJ currently is not supported, nor is the ListViewCachingStrategy.RecycleElementAndDataTemplate, but I'm working to enable that scenario too. For now, I'm trying to understand if it has some positive impact on performance, especially in item templates.

adospace commented 6 months ago

@Code-DJ I was not completely correct in the answer:

  1. componentRefAction is already supported using the new pattern:
private MauiControls.Entry? _entryRef;

public override VisualNode Render()
    => ContentPage("Element Reference",
        VStack(spacing: 10,
            Entry(entryRef => _entryRef = entryRef)
                .Text("Hi!")
                .VCenter()
                .HCenter(),

            Button("Focus Entry")
                .BackgroundColor(Colors.Green)
                .HCenter()
                .OnClicked(()=> _entryRef?.Focus())
        )
    ); 

NOTE: starting beta-10 is no longer required to use collection expressions:

before beta-10:

public override VisualNode Render()
    => ContentPage("Element Reference",
        [
             ....
        ])
    ); 

after beta-10:

public override VisualNode Render()
    => ContentPage("Element Reference",
             ....
        )
    ); 
  1. ListViewCachingStrategy is a different thing because it can't be changed after the creation of the ListView, so still not sure if and how support it using the new pattern