Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
27 changes: 27 additions & 0 deletions src/Core/src/Platform/Android/MauiHybridWebView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Android.Content;
using Android.Graphics;
using Android.Webkit;
using AUri = Android.Net.Uri;
using AWebView = Android.Webkit.WebView;
Expand All @@ -15,11 +16,37 @@ public class MauiHybridWebView : AWebView, IHybridPlatformWebView
{
private readonly WeakReference<HybridWebViewHandler> _handler;
private static readonly AUri AndroidAppOriginUri = AUri.Parse(HybridWebViewHandler.AppOrigin)!;
readonly Rect _clipRect;

public MauiHybridWebView(HybridWebViewHandler handler, Context context) : base(context)
{
ArgumentNullException.ThrowIfNull(handler, nameof(handler));
_handler = new WeakReference<HybridWebViewHandler>(handler);

// Initialize with empty clip bounds to prevent the WebView from briefly
// rendering at full screen size before layout is complete.
// https://github.com/dotnet/maui/issues/31475
_clipRect = new Rect(0, 0, 0, 0);
ClipBounds = _clipRect;
}

protected override void OnSizeChanged(int width, int height, int oldWidth, int oldHeight)
{
base.OnSizeChanged(width, height, oldWidth, oldHeight);

// Update clip bounds to match the actual size once layout is complete.
if (width > 0 && height > 0)
{
_clipRect.Set(0, 0, width, height);
ClipBounds = _clipRect;
}
Comment thread
praveenkumarkarunanithi marked this conversation as resolved.
else
{
// Reset to empty rect when the view becomes zero-sized or hidden,
// to avoid stale non-zero clip bounds.
_clipRect.Set(0, 0, 0, 0);
ClipBounds = _clipRect;
}
}

public void SendRawMessage(string rawMessage)
Expand Down
27 changes: 27 additions & 0 deletions src/Core/src/Platform/Android/MauiWebView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Android.Content;
using Android.Graphics;
using Android.Webkit;

namespace Microsoft.Maui.Platform
Expand All @@ -9,10 +10,36 @@ public class MauiWebView : WebView, IWebViewDelegate
public const string AssetBaseUrl = "file:///android_asset/";

readonly WebViewHandler _handler;
readonly Rect _clipRect;

public MauiWebView(WebViewHandler handler, Context context) : base(context)
{
_handler = handler ?? throw new ArgumentNullException(nameof(handler));

// Initialize with empty clip bounds to prevent the WebView from briefly
// rendering at full screen size before layout is complete.
// https://github.com/dotnet/maui/issues/31475
_clipRect = new Rect(0, 0, 0, 0);
ClipBounds = _clipRect;
}

protected override void OnSizeChanged(int width, int height, int oldWidth, int oldHeight)
{
base.OnSizeChanged(width, height, oldWidth, oldHeight);

// Update clip bounds to match the actual size once layout is complete.
if (width > 0 && height > 0)
{
_clipRect.Set(0, 0, width, height);
ClipBounds = _clipRect;
}
Comment thread
praveenkumarkarunanithi marked this conversation as resolved.
else
{
// Reset to empty rect when the view becomes zero-sized or hidden,
// to avoid stale non-zero clip bounds.
_clipRect.Set(0, 0, 0, 0);
ClipBounds = _clipRect;
}
}

void IWebViewDelegate.LoadHtml(string? html, string? baseUrl)
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ override Microsoft.Maui.PlatformDrawable.ThresholdType.get -> System.Type!
*REMOVED*override Microsoft.Maui.Graphics.MauiDrawable.OnBoundsChange(Android.Graphics.Rect! bounds) -> void
*REMOVED*override Microsoft.Maui.Graphics.MauiDrawable.OnDraw(Android.Graphics.Drawables.Shapes.Shape? shape, Android.Graphics.Canvas? canvas, Android.Graphics.Paint? paint) -> void
override Microsoft.Maui.Handlers.LabelHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Platform.MauiHybridWebView.OnSizeChanged(int width, int height, int oldWidth, int oldHeight) -> void
override Microsoft.Maui.Platform.MauiWebView.OnSizeChanged(int width, int height, int oldWidth, int oldHeight) -> void
Loading