diff --git a/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs b/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs index c6cfdea35039..f814825c8524 100644 --- a/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs +++ b/src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs @@ -112,6 +112,14 @@ protected override WKWebView CreatePlatformView() WebView = webview }); + // Disable bounce scrolling to make Blazor apps feel more native + if (webview.ScrollView != null) + { + webview.ScrollView.Bounces = false; + webview.ScrollView.AlwaysBounceVertical = false; + webview.ScrollView.AlwaysBounceHorizontal = false; + } + Logger.CreatedWebKitWKWebView(); return webview; diff --git a/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.Behaviors.cs b/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.Behaviors.cs new file mode 100644 index 000000000000..561f29063fe0 --- /dev/null +++ b/src/BlazorWebView/tests/MauiDeviceTests/Elements/BlazorWebViewTests.Behaviors.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components.WebView.Maui; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Maui.MauiBlazorWebView.DeviceTests.Components; +using Xunit; + +namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests.Elements; + +public partial class BlazorWebViewTests +{ +#if IOS || MACCATALYST + [Fact] + public async Task BlazorWebViewScrollBounceDisabledByDefault() + { + EnsureHandlerCreated(additionalCreationActions: appBuilder => + { + appBuilder.Services.AddMauiBlazorWebView(); + }); + + var bwv = new BlazorWebViewWithCustomFiles + { + HostPage = "wwwroot/index.html", + CustomFiles = new Dictionary + { + { "index.html", TestStaticFilesContents.DefaultMauiIndexHtmlContent }, + }, + }; + bwv.RootComponents.Add(new RootComponent { ComponentType = typeof(NoOpComponent), Selector = "#app", }); + + await InvokeOnMainThreadAsync(async () => + { + var bwvHandler = CreateHandler(bwv); + var platformWebView = bwvHandler.PlatformView; + await WebViewHelpers.WaitForWebViewReady(platformWebView); + + // Verify that bounce scrolling is disabled by default to make apps feel more native + Assert.False(platformWebView.ScrollView.Bounces); + Assert.False(platformWebView.ScrollView.AlwaysBounceVertical); + Assert.False(platformWebView.ScrollView.AlwaysBounceHorizontal); + }); + } +#endif +}