MassivePixel / Clay

React inspired library for Xamarin.Forms
MIT License
4 stars 0 forks source link

I am intrigued #1

Open Odonno opened 6 years ago

Odonno commented 6 years ago

Hi @tpetrina, I plan to make a C#/XAML component system and your library seems to be a good start. My first goal is to make a full component system for UWP apps but the long term would be to make it available for UWP/WPF and Xamarin.

I think the "virtual dom" implementation is absolutely necessary but I wonder how to stay synchronize with the XAML tree. I mean, re-rendering every time when the state change will re-render the entire page for now but I need to dig deeper to find the best way to re-render only when and only what's needed.

I have some ideas like if you do conditional rendering, display all possible UI element but set Visibility=Collapsed for all unless they are used. And of course, we should make a single reference per UI element.

I would like to share with you if you have ideas on this and if we can share some code?

tpetrina commented 6 years ago

Hi @Odonno, glad you like the idea. This project is currently stale and I had no luck getting JSX style syntax in C# needed to make this smoother. There is an alternative project made by @praeclarum called ImmutableUI https://github.com/praeclarum/ImmutableUI, might want to check that.

As for your question, typically you have a handler object that maps from v-dom to the real dom. This enables you to just toggle a property on the real object if just a single property was changed. Also, you might use Visibility or you might literally show/hide an object in UI.

On the final note, XAML has things like markup extensions, attached properties and dependency properties which are hard to translate into a simple model based on vdom. If you have some ideas I would appreciate not working alone on this :D

Odonno commented 6 years ago

The JSX style syntax can be great but it is not the primary objective. It will require a new format and a new compiler to C# code. I don't think it is too hard to do but not that urgent. I will take a look at ImmutableUI.

About the virtual dom, more likely to be named virtual XAML tree, I have more and more ideas by thinking about it. Indeed, I will have to play a lot with Name and Visibility properties. I will write some code to check my ideas first.

Yes, XAML can be a complicated thing with DP but again, I will start with simple UI.

I will try things and keep you in touch.

tpetrina commented 6 years ago

Looking forward to it! I would love us to bounce ideas off each other.

Odonno commented 6 years ago

@tpetrina I have made some experiments lately and I am pretty happy with the latest one. I made experiments using C#/XAML in UWP but I suppose it can work similarly on other platforms.

I have made a virtual XAML tree that can be optimized in a way I can reuse UIElement. It's still an early stage prototype so I only tested my code with a simple UI and there is a lot of things to try before completion.

But here is what I get so far:

Well, without code, I can understand it's a bit difficult to understand but I will continue to experiment to see if it behaves like expected on more complex UI. I also need to make a roadmap to check the long road of things that needs to be done.

I also take a look at ImmutableUI library. It looks pretty good but I chosed to use reflection instead of creating classes on top of each UIElement.

Odonno commented 6 years ago

I just found this repository https://github.com/demigor/nreact

I also find it interesting even though the project seems ambitious. I checked quickly but there is already a detailed implementation of patching which I may take inspiration for some experiments.