提交 7e139e85 编写于 作者: M Martin Zikmund

fix: Set initial Window size earlier on WASM

上级 0a675423
......@@ -110,7 +110,7 @@ namespace Windows.UI.Xaml
// Force init
Window.Current.ToString();
var arguments = WindowManagerInterop.FindLaunchArguments();
var arguments = WindowManagerInterop.BeforeLaunch();
if (this.Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug))
{
......
......@@ -96,17 +96,7 @@ namespace Windows.UI.Xaml
[JSExport]
[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)
{
......@@ -164,6 +154,7 @@ namespace Windows.UI.Xaml
}
WindowManagerInterop.SetRootElement(_rootVisual.HtmlId);
DispatchInvalidateMeasure();
if (FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded)
{
......
......@@ -28,9 +28,16 @@ namespace Uno.UI.Xaml
internal static Task InitAsync(bool isLoadEventsEnabled)
=> NativeMethods.InitAsync(isLoadEventsEnabled);
internal static string FindLaunchArguments()
=> NativeMethods.FindLaunchArguments();
/// <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();
internal static double GetBootTime()
=> NativeMethods.GetBootTime();
......@@ -1095,8 +1102,8 @@ namespace Uno.UI.Xaml
[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();
......
......@@ -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();
}
......@@ -1056,8 +1058,6 @@ namespace Uno.UI {
this.dispatchEvent(this.rootElement, "loaded");
}
this.setAsArranged(newRootElement); // patch because root is not measured/arranged
this.resize();
}
/**
......@@ -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")) {
......@@ -1679,7 +1679,7 @@ namespace Uno.UI {
}
}
private resize() {
private static resize() {
WindowManager.resizeMethod(document.documentElement.clientWidth, document.documentElement.clientHeight);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册