Skip to content

Commit

Permalink
fix: Move to jsimport for bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 22, 2024
1 parent feff443 commit 00f3ced
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
14 changes: 6 additions & 8 deletions src/Uno.UI/UI/Xaml/Window/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System.Runtime.InteropServices.JavaScript;
using Microsoft.UI.Xaml.Controls;
using System.Xml.Linq;

namespace Uno.UI.Xaml
{
Expand Down Expand Up @@ -517,14 +518,8 @@ private struct WindowManagerRegisterEventOnViewParams

internal static Rect GetBBox(IntPtr htmlId)
{
var parms = new WindowManagerGetBBoxParams
{
HtmlId = htmlId
};

var ret = (WindowManagerGetBBoxReturn)TSInteropMarshaller.InvokeJS("Uno:getBBoxNative", parms, typeof(WindowManagerGetBBoxReturn));

return new Rect(ret.X, ret.Y, ret.Width, ret.Height);
var ret = NativeMethods.GetBBox(htmlId);
return new Rect(ret[0], ret[1], ret[2], ret[3]);
}

[TSInteropMessage]
Expand Down Expand Up @@ -890,6 +885,9 @@ internal static partial void ArrangeElement(

[JSImport("globalThis.Uno.UI.WindowManager.current.setUnsetCssClasses")]
internal static partial void SetUnsetCssClasses(IntPtr htmlId, string[] cssClassesToSet, string[] cssClassesToUnset);

[JSImport("globalThis.Uno.UI.WindowManager.current.getBBox")]
internal static partial double[] GetBBox(IntPtr htmlId);

Check failure on line 890 in src/Uno.UI/UI/Xaml/Window/WindowManagerInterop.wasm.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/UI/Xaml/Window/WindowManagerInterop.wasm.cs#L890

Rename this method to not shadow the outer class' member with the same name.
}
}
}
28 changes: 8 additions & 20 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -984,24 +984,7 @@ namespace Uno.UI {
delete this.allActiveElementsById[elementId];
}

public getBBoxNative(pParams: number, pReturn: number): boolean {

const params = WindowManagerGetBBoxParams.unmarshal(pParams);

const bbox = this.getBBoxInternal(params.HtmlId);

const ret = new WindowManagerGetBBoxReturn();
ret.X = bbox.x;
ret.Y = bbox.y;
ret.Width = bbox.width;
ret.Height = bbox.height;

ret.marshal(pReturn);

return true;
}

private getBBoxInternal(elementId: number): any {
public getBBox(elementId: number): any {

const element = this.getView(elementId) as SVGGraphicsElement;
let unconnectedRoot: HTMLElement | SVGGraphicsElement = null;
Expand All @@ -1028,12 +1011,17 @@ namespace Uno.UI {
this.containerElement.appendChild(unconnectedRoot);
}

return element.getBBox();
let bbox = element.getBBox();

Check warning on line 1014 in src/Uno.UI/ts/WindowManager.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI/ts/WindowManager.ts#L1014

Identifier 'bbox' is never reassigned; use 'const' instead of 'let'.

return [
bbox.x,
bbox.y,
bbox.width,
bbox.height];
}
finally {
cleanupUnconnectedRoot(this.containerElement);
}

}

public setSvgElementRect(pParams: number): boolean {
Expand Down

0 comments on commit 00f3ced

Please sign in to comment.