Skip to content

Commit

Permalink
trytofixios
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebaltazar committed Nov 2, 2024
1 parent 87b7285 commit 9725bc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions Maui.ServerDrivenUI/Models/ServerUIElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Maui.ServerDrivenUI.Services;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;

namespace Maui.ServerDrivenUI;

Expand Down Expand Up @@ -113,9 +114,19 @@ public string ToXaml(IList<CustomNamespace>? customNamespaces = null)
}

var xaml = XamlConverterService.ConvertToXml(this);
return $"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
$"{xaml}";
return DoRemovespace($"<?xml version=\"1.0\" ?>\n" +
$"{xaml}");
}

#endregion

private static string DoRemovespace(string strFile)
{
var str = System.IO.File.ReadAllText(strFile);
str = str.Replace("\n", "");
str = str.Replace("\r", "");
var regex = new Regex(@">\s*<");
return regex.Replace(str, "><");

}
}
5 changes: 3 additions & 2 deletions Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e
var errorMessage = string.Empty;
try
{
ShowLoadingView(element);
MainThread.BeginInvokeOnMainThread(() => ShowLoadingView(element));
MainThread.BeginInvokeOnMainThread(() => element.State = UIElementState.Loading);
await Task.Yield();

var serverDrivenUiService = ServiceProviderHelper
.ServiceProvider?
.GetService<IServerDrivenUIService>();

if (serverDrivenUiService != null)
if (serverDrivenUiService is not null)
{
var xaml = await serverDrivenUiService
.GetXamlAsync(element.ServerKey ?? element.GetType().Name)
Expand Down

0 comments on commit 9725bc9

Please sign in to comment.