HotUI is an MVU UIToolkit written in C#
Перейти к файлу
jonlipsky 5462494722
Merge pull request #97 from twsouthwick/blazor
Enable progress bar, images, and breadcrumb navigation in Blazor
2019-07-25 10:31:13 -07:00
build Removed Forms from the mac build 2019-07-22 21:02:42 -07:00
sample Add image handler and middleware 2019-07-25 09:44:38 -07:00
src Add breadcrumb navigation 2019-07-25 09:44:38 -07:00
tests/HotUI.Tests Added new type system to the Styles, Text color now works. 2019-07-23 21:46:50 -07:00
.gitattributes Added GitAttributes 2019-07-15 23:24:50 -08:00
.gitignore Added initial implemention for Android 2019-06-23 21:00:02 -06:00
HotUI.Blazor.sln Add initial blazor support 2019-07-23 17:21:01 -07:00
HotUI.nuspec yaml nuget updated, nuspec updaed 2019-07-22 11:38:45 -07:00
HotUI.sln Removed Forms project from solution. 2019-07-22 20:00:14 -07:00
HotUI.sln.DotSettings Skia works on iOS and Mac. 2019-07-19 15:58:35 -05:00
LICENSE Started on iOS version! 2019-06-21 13:30:03 -08:00
README.md Update README.md 2019-07-24 01:51:42 +02:00

README.md

HotUI

Gitter

What is HotUI? HotUI is a prototype for a new UI Framework/Pattern to write app UI. It follows the Model View Update (MVU) pattern. It magically databinds for you!

Key Concepts

HotUI is an MVU style pattern.

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

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

or:

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

Hot Reload

Hot Reload is included by default! The setup is very easy: a Visual Studio extension and a NuGet. Download both from Releases here on GitHub.

Download and install the VS extension from the Releases

Then add to your AppDelegate.cs and/or MainActivity.cs, or similar. See the sample projects here for examples.

 #if DEBUG
            HotUI.Reload.Init();
 #endif

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 will be supported?

  • iOS
  • Android
  • UWP
  • WPF
  • Mac OS
  • Xamarin.Forms
  • Blazor

Disclaimer

HotUI is a proof of concept. There is no official support. Use at your own Risk.