Skip to content

Commit

Permalink
perf(WindowManager): Add GetAttribute binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Mar 24, 2023
1 parent 9f57900 commit 9a46fda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/Uno.UI/UI/Xaml/UIElement.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ protected internal void SetAttribute(params (string name, string value)[] attrib

protected internal string GetAttribute(string name)
{
var command = "Uno.UI.WindowManager.current.getAttribute(" + HtmlId + ", \"" + name + "\");";
return WebAssemblyRuntime.InvokeJS(command);
return WindowManagerInterop.GetAttribute(HtmlId, name);
}

protected internal void SetProperty(string name, string value)
Expand Down
7 changes: 7 additions & 0 deletions src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,13 @@ private struct WindowManagerSetAttributeParams
#region GetAttribute
internal static string GetAttribute(IntPtr htmlId, string name)
{
#if NET7_0_OR_GREATER
return NativeMethods.GetAttribute(htmlId, name);
#else
var command = "Uno.UI.WindowManager.current.getAttribute(\"" + htmlId + "\", \"" + name + "\");";

return WebAssemblyRuntime.InvokeJS(command);
#endif
}
#endregion

Expand Down Expand Up @@ -1193,6 +1197,9 @@ internal static partial void ArrangeElement(
[JSImport("globalThis.Uno.UI.WindowManager.current.destroyViewNativeFast")]
internal static partial void DestroyView(IntPtr htmlId);

[JSImport("globalThis.Uno.UI.WindowManager.current.getAttribute")]
internal static partial string GetAttribute(IntPtr htmlId, string name);

[JSImport("globalThis.Uno.UI.WindowManager.current.measureViewNativeFast")]
internal static partial void MeasureView(IntPtr htmlId, double availableWidth, double availableHeight, bool measureContent, IntPtr pReturn);

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ namespace Uno.UI {
/**
* Get an attribute for an element.
*/
public getAttribute(elementId: number, name: string): any {
public getAttribute(elementId: number, name: string): string {

return this.getView(elementId).getAttribute(name);
}
Expand Down

0 comments on commit 9a46fda

Please sign in to comment.