Skip to content

Commit

Permalink
fix: Set initial Window size earlier on WASM
Browse files Browse the repository at this point in the history
(cherry picked from commit 7e139e8)

# Conflicts:
#	src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
  • Loading branch information
MartinZikmund authored and mergify[bot] committed Aug 8, 2023
1 parent 8d4e098 commit a883ba8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Application.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void Initialize()
// Force init
Window.Current.ToString();

var arguments = WindowManagerInterop.FindLaunchArguments();
var arguments = WindowManagerInterop.BeforeLaunch();

if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
{
Expand Down
13 changes: 2 additions & 11 deletions src/Uno.UI/UI/Xaml/Window.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,7 @@ private void DispatchInvalidateMeasure()
[JSExport]
#endif
[Preserve]
public static void Resize(double width, double height)
{
var window = Current?._rootVisual;
if (window == null)
{
typeof(Window).Log().Error($"Resize ignore, no current window defined");
return; // nothing to measure
}

Current.OnNativeSizeChanged(new Size(width, height));
}
public static void Resize(double width, double height) => Current.OnNativeSizeChanged(new Size(width, height));

private void OnNativeSizeChanged(Size size)
{
Expand Down Expand Up @@ -173,6 +163,7 @@ private void InternalSetContent(UIElement content)
}

WindowManagerInterop.SetRootElement(_rootVisual.HtmlId);
DispatchInvalidateMeasure();

if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded)
{
Expand Down
17 changes: 15 additions & 2 deletions src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,26 @@ internal static Task InitAsync(bool isLoadEventsEnabled)
WebAssemblyRuntime.InvokeAsync($"Uno.UI.WindowManager.init({(isLoadEventsEnabled ? "true" : "false")})");
#endif

<<<<<<< HEAD
internal static string FindLaunchArguments()
=>
#if NET7_0_OR_GREATER
NativeMethods.FindLaunchArguments();
#else
WebAssemblyRuntime.InvokeJS("Uno.UI.WindowManager.findLaunchArguments()");
#endif
=======
/// <summary>
/// This method has two purposes:
/// - Initializes the window size before launch
/// - Returns the app arguments
/// The reason for having two concerns in one method
/// is to avoid unnecessary roundtrip between JS and C#.
/// </summary>
/// <returns>App launch arguments.</returns>
internal static string BeforeLaunch()
=> NativeMethods.BeforeLaunch();
>>>>>>> 7e139e85ea (fix: Set initial Window size earlier on WASM)

internal static double GetBootTime()
=>
Expand Down Expand Up @@ -1323,8 +1336,8 @@ internal static partial void ArrangeElement(
[JSImport("globalThis.Uno.UI.WindowManager.current.destroyViewNativeFast")]
internal static partial void DestroyView(IntPtr htmlId);

[JSImport("globalThis.Uno.UI.WindowManager.findLaunchArguments")]
internal static partial string FindLaunchArguments();
[JSImport("globalThis.Uno.UI.WindowManager.beforeLaunch")]
internal static partial string BeforeLaunch();

[JSImport("globalThis.Uno.UI.WindowManager.getBootTime")]
internal static partial double GetBootTime();
Expand Down
10 changes: 5 additions & 5 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ namespace Uno.UI {
* Reads the window's search parameters
*
*/
static findLaunchArguments(): string {
static beforeLaunch(): string {
WindowManager.resize();

if (typeof URLSearchParams === "function") {
return new URLSearchParams(window.location.search).toString();
}
Expand Down Expand Up @@ -1056,8 +1058,6 @@ namespace Uno.UI {
this.dispatchEvent(this.rootElement, "loaded");
}
this.setAsArranged(newRootElement); // patch because root is not measured/arranged

this.resize();
}

/**
Expand Down Expand Up @@ -1656,7 +1656,7 @@ namespace Uno.UI {
document.body.addEventListener("focusin", this.onfocusin);
document.body.appendChild(this.containerElement);

window.addEventListener("resize", x => this.resize());
window.addEventListener("resize", x => WindowManager.resize());
window.addEventListener("contextmenu", x => {
if (!(x.target instanceof HTMLInputElement) ||
x.target.classList.contains("context-menu-disabled")) {
Expand All @@ -1679,7 +1679,7 @@ namespace Uno.UI {
}
}

private resize() {
private static resize() {
WindowManager.resizeMethod(document.documentElement.clientWidth, document.documentElement.clientHeight);
}

Expand Down

0 comments on commit a883ba8

Please sign in to comment.