Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move to jsimport for bbox #18900

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@

[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 @@
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 @@
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
Loading