Skip to content

[NET10] Replace the obsolete RunJavaScriptTextInputPanel - #28531

Merged
PureWeen merged 12 commits into
net10.0from
fix-28135
Jun 6, 2025
Merged

[NET10] Replace the obsolete RunJavaScriptTextInputPanel #28531
PureWeen merged 12 commits into
net10.0from
fix-28135

Conversation

@jsuarezruiz

@jsuarezruiz jsuarezruiz commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

Description of Change

This pull request introduces several enhancements and fixes across the Maui platform, focusing on improving iOS support, adding new functionality to Blazor components, and refining public APIs. Key changes include enabling unsafe code blocks, extending iOS-specific features, and adding user interaction capabilities in Blazor components.

Changes to iOS-specific functionality:

  • Made UIApplicationExtensions public and added GetKeyWindow and GetWindow extension methods to simplify window management in iOS. (src/Core/src/Platform/iOS/UIApplicationExtensions.cs, src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt, src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt) [1] [2] [3]
  • Updated IOSWebViewManager to use GetKeyWindow instead of deprecated UIApplication.Windows for compatibility with iOS 15+ and introduced ActionStringTrampolineBlock for handling unmanaged function pointers. (src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs) [1] [2]

Enhancements to Blazor components:

  • Added new buttons (Decrement and Set Value) to the Blazor sample app, enabling user interactions with JavaScript for confirmation dialogs, prompts, and alerts. (src/Controls/samples/Controls.Sample/Pages/Blazor/Index.razor)

Build and project settings:

  • Enabled the AllowUnsafeBlocks property in the Microsoft.AspNetCore.Components.WebView.Maui.csproj file to allow unsafe code usage. (src/BlazorWebView/src/Maui/Microsoft.AspNetCore.Components.WebView.Maui.csproj)

These changes improve compatibility, enhance functionality, and refine user interactions within the Maui platform and Blazor components.

Issues Fixed

Fixes #28135

@jsuarezruiz jsuarezruiz added area-blazor Blazor Hybrid / Desktop, BlazorWebView t/housekeeping ♻︎ labels Mar 20, 2025
Copilot AI review requested due to automatic review settings March 20, 2025 11:07
@jsuarezruiz
jsuarezruiz requested review from a team as code owners March 20, 2025 11:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the obsolete RunJavaScriptTextInputPanel with a new public API method and adds a decrement functionality in the Blazor sample page.

  • Replaces the obsolete method with a new signature and updated parameter list in the iOS WebView manager.
  • Removes deprecated warning suppression and updates logic for presenting the alert controller.
  • Introduces a new Decrement button and corresponding logic in the Blazor sample page with a JavaScript confirmation.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs Replaces obsolete RunJavaScriptTextInputPanel with new ShowJavaScriptTextInputPanel and adjusts alert controller presentation logic.
src/Controls/samples/Controls.Sample/Pages/Blazor/Index.razor Adds a new Decrement button with confirmation functionality via JSRuntime.
Comments suppressed due to low confidence (1)

src/Controls/samples/Controls.Sample/Pages/Blazor/Index.razor:23

  • The new Decrement method with asynchronous confirmation should be accompanied by test cases in TestCases.HostApp and TestCases.Shared.Tests.
async Task Decrement()

Comment thread src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs Outdated
@jsuarezruiz
jsuarezruiz marked this pull request as draft March 20, 2025 11:13
Comment thread src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs
@jsuarezruiz jsuarezruiz changed the title [net10.0] Replace the obsolete RunJavaScriptTextInputPanel [NET10] Replace the obsolete RunJavaScriptTextInputPanel Mar 20, 2025
@PureWeen PureWeen added this to the .NET 10.0-preview4 milestone Apr 8, 2025
@rmarinho
rmarinho requested a review from mattleibow May 6, 2025 17:33
@jsuarezruiz
jsuarezruiz marked this pull request as ready for review May 8, 2025 15:57
Comment thread src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs
@github-project-automation github-project-automation Bot moved this from Todo to Changes Requested in MAUI SDK Ongoing May 13, 2025

@rmarinho rmarinho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems tests are failing

https://dev.azure.com/xamarin/public/_build/results?buildId=142178&view=ms.vss-test-web.build-test-results-tab&runId=4160051&resultId=100030&paneView=attachments

/_/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs(16707566): error MT4174: Unable to locate the block to delegate conversion method for the method System.Void Microsoft.AspNetCore.Components.WebView.Maui.IOSWebViewManager/WebViewUIDelegate::RunJavaScriptTextInputPanelWithPrompt(WebKit.WKWebView,Foundation.NSString,Foundation.NSString,WebKit.WKFrameInfo,System.Action`1<Foundation.NSString>)'s parameter #5. [/Users/builder/azdo/_work/_temp/test-dir/BuildWithDiffer1382439389/BuildWithDiffer1382439389.csproj::TargetFramework=net10.0-maccatalyst]

@jsuarezruiz

Copy link
Copy Markdown
Contributor Author

Seems tests are failing

https://dev.azure.com/xamarin/public/_build/results?buildId=142178&view=ms.vss-test-web.build-test-results-tab&runId=4160051&resultId=100030&paneView=attachments

/_/src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs(16707566): error MT4174: Unable to locate the block to delegate conversion method for the method System.Void Microsoft.AspNetCore.Components.WebView.Maui.IOSWebViewManager/WebViewUIDelegate::RunJavaScriptTextInputPanelWithPrompt(WebKit.WKWebView,Foundation.NSString,Foundation.NSString,WebKit.WKFrameInfo,System.Action`1<Foundation.NSString>)'s parameter #5. [/Users/builder/azdo/_work/_temp/test-dir/BuildWithDiffer1382439389/BuildWithDiffer1382439389.csproj::TargetFramework=net10.0-maccatalyst]

Should be fixed with the latest changes.

rmarinho
rmarinho previously approved these changes Jun 5, 2025
@mattleibow

Copy link
Copy Markdown
Member

/rebase

Comment thread src/Core/src/Platform/iOS/UIApplicationExtensions.cs

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic is to use the fancy code from dotnet/macios#15728 (comment)

Right now this PR still throws if null is used.

I'll update

Comment thread src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs

@mattleibow mattleibow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs
Comment thread src/Core/src/Platform/iOS/UIApplicationExtensions.cs
@github-project-automation github-project-automation Bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Jun 5, 2025
@PureWeen
PureWeen merged commit 1a0b41d into net10.0 Jun 6, 2025
@PureWeen
PureWeen deleted the fix-28135 branch June 6, 2025 15:33
@github-project-automation github-project-automation Bot moved this from Approved to Done in MAUI SDK Ongoing Jun 6, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-blazor Blazor Hybrid / Desktop, BlazorWebView proposal/open t/housekeeping ♻︎

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants