Comet is an MVU UIToolkit written in C#
Перейти к файлу
James Clancey 3ee062c5e0 Added frameconstraint lerp 2022-05-02 10:53:24 -08:00
.github/workflows Updated main build file 2022-04-27 11:40:19 -08:00
.vscode Added VSCode settings 2019-12-15 18:50:41 -09:00
External Working on fixing the RC Build 2022-04-26 14:59:47 -08:00
art Add MVU pattern image 2020-01-22 07:53:36 +01:00
build Update install-vs.ps1 2022-04-12 10:06:22 -08:00
sample Working on fixing the RC Build 2022-04-26 14:59:47 -08:00
src Added frameconstraint lerp 2022-05-02 10:53:24 -08:00
templates Updated template 2022-04-27 13:18:32 -08:00
tests Updated the sample and template 2021-11-09 17:52:23 -09:00
.editorconfig Remove *.md from .editorconfig 2021-09-23 17:42:05 +07:00
.gitattributes Added GitAttributes 2019-07-15 23:24:50 -08:00
.gitignore Fixed 2 way bindings!!!! 2019-08-07 11:29:11 -04:00
.gitmodules Switched to dotnet/Maui repo 2021-04-06 14:32:11 -08:00
CODE-OF-CONDUCT.md Add CoC (#185) 2021-02-19 15:54:10 -09:00
Comet-net6.sln Updated to latest Maui 2022-02-03 14:04:58 -09:00
Comet.Blazor.sln Blazor Code formatting 2019-12-13 10:04:23 -09:00
Comet.Reload.nuspec Updated the sample and template 2021-11-09 17:52:23 -09:00
Comet.Skia.nuspec Adding proper comet dependency 2020-01-17 14:09:31 -09:00
Comet.WinUI.sln Windows now builds properly. Sample still needs updating 2021-07-12 19:25:57 -08:00
Comet.nuspec Added standard net-6 to the nuget 2022-03-16 14:01:43 -08:00
Comet.sln Builds again on the latest Maui 2021-10-11 16:46:48 -08:00
Comet.sln.DotSettings Fixed layout issue and added text alignment. 2019-09-12 16:04:32 -05:00
Directory.Build.props Updated to RC 2022-04-06 12:43:50 -08:00
Directory.Build.targets Add the Build.Props to the nuget. Cleanup the nuget stuff 2022-01-10 18:16:36 -08:00
LICENSE Started on iOS version! 2019-06-21 13:30:03 -08:00
NuGet.config Update NuGet.config 2022-03-04 15:32:46 -09:00
README.md grammar, spelling, casing 2021-12-13 21:51:53 -09:00
global.json Create global.json 2022-03-17 08:08:25 -08:00

README.md

Comet ☄️

dev-build Clancey.Comet on fuget.org Chat on Discord

What is Comet? Comet is a modern way of writing cross-platform UIs. Based on .NET MAUI, it follows the Model View Update (MVU) pattern and magically databinds for you!

Watch this video to get a preview of the developer experience:

Video Demo

Getting Started

When you're ready to take a ride on the Comet, head over to the wiki and follow the Getting Started guide.

Key Concepts

Comet is based on the MVU architecture:

MVU pattern

View is a screen. Views have a Body method that you can assign either by using an attribute [Body]:

public class MyPage : View {
    [Body]
    View body () => new Text("Hello World");
}

Or manually from your constructor:

public class MyPage : View {
    public MyPage() {
        Body = body;
    }
    View body () => new Text("Hello World");
}

Hot Reload

Using Hot Reload is the fastest way to develop your user interface.

The setup is simple and only requires a few steps:

  1. Install the Visual Studio extension Comet.Reload from Releases (or Comet for .NET Mobile if you use Visual Studio Code)
  2. Install the Comet project template available on NuGet.
  3. Add this short snippet to your AppDelegate.cs and/or MainActivity.cs, or equivalent.
#if DEBUG
Comet.Reload.Init();
#endif

See the sample projects here for examples.

State

As of right now there are two supported ways to add state.

1. Simple data types like int, bool?

Just add a State<T> field to your View

class MyPage : View {
    readonly State<int> clickCount = 1;
}

View is state aware. When the state changes, databinding will automatically update, or rebuild the view as needed.

2. Do you want to use more complex data types?

You can either implement INotifyPropertyRead or you can use BindingObject to make it even simpler.

Add it as a Field/Property, and add the [State] attribute!

public class MainPage : View {
    class MyBindingObject : BindingObject {
        public bool CanEdit {
            get => GetProperty<bool> ();
            set => SetProperty (value);
        }
        public string Text {
            get => GetProperty<string> ();
            set => SetProperty (value);
        }
    }

    [State]
    readonly MyBindingObject state;
}

INotifyPropertyRead is just like INotifyPropertyChanged. Just call PropertyRead whenever a property getter is called. And PropertyChanged whenever a property value changes.

How do I use the State?

Simply update the stateful value and the framework handles the rest.

public class MyPage : View {

    readonly State<int> clickCount = 1;
    readonly State<string> text = "Hello World";

    public MyPage() {
        Body = () => new VStack {
            new Text (text),
            new Button("Update Text", () => state.Text = $"Click Count: {clickCount.Value++}")
        };

    }
}

That is all!, now when the text changes everything updates.

What if I want to format my value without an extra state property?

While new Button("Update Text", () => state.Text = $"Click Count: {clickCount.Value++}" ) works, it isn't efficient.

Instead, use new Text(()=> $"Click Count: {clickCount}").

public class MyPage : View {

    readonly State<int> clickCount = new State<int> (1);

    public MyPage() {
        Body = () => new VStack {
            new Text (() => $"Click Count: {clickCount}"),
            new Button("Update Text", () => {
                clickCount.Value++;
            }
        };
    }
}

What platforms are supported?

Comet is developed on top of .NET MAUI handlers, providing its own implementation for interfaces such as Microsoft.Maui.IButton and other controls. Any platform supported by .NET MAUI can be targeted:

  • Windows
  • Android
  • iOS
  • macOS
  • Blazor

Non-MAUI application models, such as UWP or WPF, are not supported.

Disclaimer

Comet is a proof of concept. There is no official support. Use at your own risk.