diff --git a/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs b/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs index 0ed4846412ae..652164ccf494 100644 --- a/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs +++ b/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.cs @@ -83,7 +83,7 @@ public partial class HybridWebViewHandler : IHybridWebViewHandler public static IPropertyMapper Mapper = new PropertyMapper(ViewHandler.ViewMapper) { -#if WINDOWS +#if WINDOWS || IOS || MACCATALYST [nameof(IView.FlowDirection)] = MapFlowDirection, #endif }; diff --git a/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.iOS.cs b/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.iOS.cs index a3e47eef5278..148720ee070f 100644 --- a/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.iOS.cs +++ b/src/Core/src/Handlers/HybridWebView/HybridWebViewHandler.iOS.cs @@ -77,6 +77,15 @@ internal static void EvaluateJavaScript(IHybridWebViewHandler handler, IHybridWe handler.PlatformView.EvaluateJavaScript(request); } + internal static void MapFlowDirection(IHybridWebViewHandler handler, IHybridWebView hybridWebView) + { + var scrollView = handler.PlatformView?.ScrollView; + if (scrollView == null) + return; + + scrollView.UpdateFlowDirectionForScrollView(hybridWebView); + } + public static void MapSendRawMessage(IHybridWebViewHandler handler, IHybridWebView hybridWebView, object? arg) { if (arg is not HybridWebViewRawMessage hybridWebViewRawMessage || handler.PlatformView is not IHybridPlatformWebView hybridPlatformWebView) diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.cs b/src/Core/src/Handlers/WebView/WebViewHandler.cs index b4dbad5fad5c..7d1fe994ee17 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.cs @@ -31,7 +31,8 @@ public partial class WebViewHandler : IWebViewHandler [nameof(WebViewClient)] = MapWebViewClient, [nameof(WebChromeClient)] = MapWebChromeClient, [nameof(WebView.Settings)] = MapWebViewSettings -#elif __IOS__ +#elif __IOS__ || MACCATALYST + [nameof(IWebView.FlowDirection)] = MapFlowDirection, [nameof(WKUIDelegate)] = MapWKUIDelegate, [nameof(IWebView.Background)] = MapBackground, #endif diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs index 7d7b83f0a58f..856b247a723e 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs @@ -64,6 +64,15 @@ public static void MapGoForward(IWebViewHandler handler, IWebView webView, objec handler.PlatformView?.UpdateGoForward(webView); } + internal static void MapFlowDirection(IWebViewHandler handler, IWebView webView) + { + var scrollView = handler.PlatformView?.ScrollView; + if (scrollView == null) + return; + + scrollView.UpdateFlowDirectionForScrollView(webView); + } + public static async void MapReload(IWebViewHandler handler, IWebView webView, object? arg) { var platformHandler = handler as WebViewHandler; diff --git a/src/Core/src/Platform/iOS/WebViewExtensions.cs b/src/Core/src/Platform/iOS/WebViewExtensions.cs index 4a16dd083600..1975044d329a 100644 --- a/src/Core/src/Platform/iOS/WebViewExtensions.cs +++ b/src/Core/src/Platform/iOS/WebViewExtensions.cs @@ -64,6 +64,29 @@ internal static void UpdateCanGoBackForward(this WKWebView platformWebView, IWeb webView.CanGoForward = platformWebView.CanGoForward; } + internal static void UpdateFlowDirectionForScrollView(this UIKit.UIScrollView scrollView, IView view) + { + scrollView.UpdateFlowDirection(view); + + // On macOS, we need to refresh the scroll indicators when flow direction changes + // But only for runtime changes, not during initial load + // The view.IsLoadedOnPlatform() check ensures that this code is executed + // only after the view has been loaded on the platform. During the initial load, + // the scroll indicators do not need to be refreshed as they are set up correctly + // by default. This avoids unnecessary operations during the initial load phase. + if (OperatingSystem.IsMacCatalyst() && view.IsLoadedOnPlatform()) + { + bool showsVertical = scrollView.ShowsVerticalScrollIndicator; + bool showsHorizontal = scrollView.ShowsHorizontalScrollIndicator; + + scrollView.ShowsVerticalScrollIndicator = false; + scrollView.ShowsHorizontalScrollIndicator = false; + + scrollView.ShowsVerticalScrollIndicator = showsVertical; + scrollView.ShowsHorizontalScrollIndicator = showsHorizontal; + } + } + public static void Eval(this WKWebView platformWebView, IWebView webView, string script) { platformWebView.EvaluateJavaScriptAsync(script);