Skip to content

[NET10] Replace the obsolete RunJavaScriptTextInputPanel #28531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 6, 2025
Merged

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Mar 20, 2025

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 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
Copy link
Contributor

@Copilot Copilot AI left a comment

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()

@jsuarezruiz jsuarezruiz marked this pull request as draft March 20, 2025 11:13
@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
@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing May 13, 2025
Copy link
Member

@rmarinho rmarinho left a comment

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
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
Member

/rebase

Copy link
Member

@mattleibow mattleibow left a comment

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

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

LGTM

@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
131 checks passed
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Blazor Hybrid / Desktop, BlazorWebView proposal/open t/housekeeping ♻︎
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants