Skip to content

Commit

Permalink
Merge pull request #116 from FmgLib/114-hotreload-new-systems
Browse files Browse the repository at this point in the history
114 hotreload new systems
  • Loading branch information
gonultasmf authored Aug 19, 2024
2 parents 68d42ec + 03bf81f commit d1361f4
Show file tree
Hide file tree
Showing 4 changed files with 1,246 additions and 31 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,53 @@ public class NumericValidationTriggerAction : TriggerAction<Entry>
}
```

# .NET built-in Hot-Reload

Additionally, the FmgLib.MauiMarkup library includes hot reload support to make the development process faster and more efficient.

If you want to enhance your page with fast reload, your page needs to implement the IFmgLibHotReload interface. Then, you should trigger the this.InitializeHotReload(); function within the constructor.

And you can write your design code inside the `Build()` method to enhance it with fast reload.

Example usage is as follows:

```csharp
public partial class ExamplePage : ContentPage, IFmgLibHotReload
{
public ExamplePage()
{
this.InitializeHotReload();
}
public void Build()
{
this
.Content(
new Label()
.Text("FmgLib.MauiMarkup")
.CharacterSpacing(2)
.FontSize(30)
.FontAttributes(Italic)
.TextColor(Green)
.TextCenter()
);
}
}
```

And here is the definition of the `NumericValidationTriggerAction` class:

```csharp
public class NumericValidationTriggerAction : TriggerAction<Entry>
{
protected override void Invoke(Entry entry)
{
double result;
bool isValid = Double.TryParse(entry.Text, out result);
entry.TextColor = isValid ? Colors.Black : Colors.Red;
}
}
```

# Extensions for 3rd Party Controls

FmgLib.MauiMarkup library can also generate extension methods for controls from third-party libraries. To achieve this, you should utilize the `MauiMarkupAttribute` provided by FmgLib.MauiMarkup.
Expand Down
2 changes: 1 addition & 1 deletion libs/FmgLib.MauiMarkup/FmgLib.MauiMarkup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageId>FmgLib.MauiMarkup</PackageId>
<Summary>FmgLib.MauiMarkup with C# Markup classes and fluent helper methods</Summary>
<Title>FmgLib.MauiMarkup</Title>
<Version>8.6.7</Version>
<Version>8.7.0</Version>
<Authors>FmgYazılım</Authors>
<Company>Fmg Yazılım</Company>
<Copyright>©2024</Copyright>
Expand Down
24 changes: 24 additions & 0 deletions libs/FmgLib.MauiMarkup/Handlers/HotReloadExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Diagnostics;

namespace FmgLib.MauiMarkup;

public static class HotReloadExtensions
{
public static TPage InitializeHotReload<TPage>(this TPage page) where TPage : IFmgLibHotReload
{
page.Build();

if (Debugger.IsAttached)
{
FmgLibHotReloadHandler.UpdateApplicationEvent += (types) =>
{
if (types == null || types.Contains(page.GetType()))
{
MainThread.BeginInvokeOnMainThread(page.Build);
}
};
}

return page;
}
}
Loading

0 comments on commit d1361f4

Please sign in to comment.