Skip to content

Commit b080921

Browse files
committed
perf(WindowManager): Add SetPropertyNativeFast binding
1 parent c4c3b68 commit b080921

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,15 +915,18 @@ internal static void SetProperty(IntPtr htmlId, (string name, string value)[] pr
915915
pairs[i * 2 + 1] = properties[i].value;
916916
}
917917

918-
var parms = new WindowManagerSetAttributesParams()
918+
#if NET7_0_OR_GREATER
919+
NativeMethods.SetProperties(htmlId, pairs);
920+
#else
921+
var parms = new WindowManagerSetPropertyParams()
919922
{
920923
HtmlId = htmlId,
921924
Pairs_Length = pairs.Length,
922925
Pairs = pairs,
923926
};
924927

925928
TSInteropMarshaller.InvokeJS("Uno:setPropertyNative", parms);
926-
929+
#endif
927930
}
928931
}
929932

@@ -1593,6 +1596,9 @@ internal static partial void ArrangeElement(
15931596
[JSImport("globalThis.Uno.UI.WindowManager.current.setPointerEventsNativeFast")]
15941597
internal static partial void SetPointerEvents(IntPtr htmlId, bool enabled);
15951598

1599+
[JSImport("globalThis.Uno.UI.WindowManager.current.setPropertyNativeFast")]
1600+
internal static partial void SetProperties(IntPtr htmlId, string[] pairs);
1601+
15961602
[JSImport("globalThis.Uno.UI.WindowManager.current.setStyleStringNativeFast")]
15971603
internal static partial void SetStyleString(IntPtr htmlId, string name, string value);
15981604

src/Uno.UI/ts/WindowManager.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,22 +536,32 @@ namespace Uno.UI {
536536
public setPropertyNative(pParams: number): boolean {
537537

538538
const params = WindowManagerSetPropertyParams.unmarshal(pParams);
539-
const element = this.getView(params.HtmlId);
540539

541-
for (let i = 0; i < params.Pairs_Length; i += 2) {
542-
const setVal = params.Pairs[i + 1];
540+
this.setPropertyNativeFast(params.HtmlId, params.Pairs);
541+
542+
return true;
543+
}
544+
545+
public setPropertyNativeFast(htmlId: number, pairs: string[]) {
546+
547+
const element = this.getView(htmlId);
548+
549+
const length = pairs.length;
550+
551+
for (let i = 0; i < length; i += 2) {
552+
553+
const setVal = pairs[i + 1];
554+
543555
if (setVal === "true") {
544-
(element as any)[params.Pairs[i]] = true;
556+
(element as any)[pairs[i]] = true;
545557
}
546558
else if (setVal === "false") {
547-
(element as any)[params.Pairs[i]] = false;
559+
(element as any)[pairs[i]] = false;
548560
}
549561
else {
550-
(element as any)[params.Pairs[i]] = setVal;
562+
(element as any)[pairs[i]] = setVal;
551563
}
552564
}
553-
554-
return true;
555565
}
556566

557567
/**

0 commit comments

Comments
 (0)