[iOS 26] Fix DisplayPromptAsync maxLength not enforced due to new multi-range delegate#33616
Conversation
|
Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
@Shalini-Ashokan Thank you for taking the time to fix it, I've tested the artifact and confirm that it fixes the maxLength issue. |
@darrabam, I have investigated and found that this appears to be a native-level issue. I have attached a video of a native sample for reference. iOS26-Alignment.mov |
|
@Shalini-Ashokan fair enough, I also tried different combinations of RTL marks (\u202B , \u202E, \u2067, \u061C), but none of them forced the text to RTL. Let's hope that this is just a bug in iOS26.1 and will be resolved in further updates. @jfversluis could you please review this PR? I've tested it and it resolves the issue, thanks! |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug on iOS 26 where DisplayPromptAsync ignores the maxLength parameter, allowing users to enter unlimited characters. The issue occurs because iOS 26 introduced a new delegate method ShouldChangeCharactersInRanges that accepts multiple text ranges, replacing the older ShouldChangeCharacters method which is no longer invoked on iOS 26.
Changes:
- Added runtime version check to use the appropriate delegate method based on iOS version
- Implemented new multi-range delegate logic for iOS 26+ that sums all range lengths and validates against maxLength
- Maintained backward compatibility by keeping the old single-range delegate for iOS versions prior to 26
src/Controls/src/Core/Platform/AlertManager/AlertManager.iOS.cs
Outdated
Show resolved
Hide resolved
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
…ti-range delegate (#33616) <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit. ### Root Cause iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break. ### Description of Change A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength. Validated the behavior in the following platforms - [x] Android - [x] Windows - [x] iOS - [x] Mac ### Issues Fixed Fixes #33549 ### Test case In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium. ### Output ScreenShot |Before|After| |--|--| | <video src="https://github.com/user-attachments/assets/e9c48ea5-1dc8-42da-a5a2-b7de13df39cd" >| <video src="https://github.com/user-attachments/assets/5324954b-d4dd-4013-a3c8-3f5c34a845cf">|
.NET MAUI inflight/candidate introduces significant improvements across all platforms with focus on quality, performance, and developer experience. This release includes 20 commits with various improvements, bug fixes, and enhancements. ## Blazor - Fix for BlazorWebView Back Navigation Issues on Android 13+ After Predictive Back Gesture Changes by @SuthiYuvaraj in #33213 <details> <summary>🔧 Fixes</summary> - [Back navigation different between .net 9 and .net 10 blazor hybrid](#32767) </details> ## CollectionView - [Android] Fix for CollectionView.EmptyView does not remeasure its height when the parent layout changes dynamically, causing incorrect sizing. by @BagavathiPerumal in #33559 <details> <summary>🔧 Fixes</summary> - [`CollectionView.EmptyView` does not remeasure its height when the parent layout changes dynamically, causing incorrect sizing.](#33324) </details> - [Android] Fixed CollectionView reordering last item by @vitalii-vov in #17825 <details> <summary>🔧 Fixes</summary> - [Android app crashes when dragging into CollectionView](#17823) </details> ## DateTimePicker - [iOS] Fix VoiceOver focus not shifting to Picker/DatePicker/TimePicker popups by @kubaflo in #33152 <details> <summary>🔧 Fixes</summary> - [Voiceover does not automatically shift focus to the "Category" popup when it opens.: A11y_Developer balance version .NET 10_Project_ScreenReader](#30746) </details> ## Dialogalert - [iOS 26] Fix DisplayPromptAsync maxLength not enforced due to new multi-range delegate by @Shalini-Ashokan in #33616 <details> <summary>🔧 Fixes</summary> - [[iOS 26.1] DisplayPromptAsync ignores maxLength and does not respect RTL FlowDirection](#33549) </details> ## Flyout - [iOS] Shell: Account for SafeArea when positioning flyout footer by @kubaflo in #32891 <details> <summary>🔧 Fixes</summary> - [[IOS] Footer not displaying in iOS when StackOrientation.Horizontal is set on FlyoutFooter](#26395) </details> ## Fonts - Hide obsolete FontSize values from IDE autocomplete by @noiseonwires in #33694 ## Gestures - Android pan fixes by @BurningLights in #21547 <details> <summary>🔧 Fixes</summary> - [Flickering occurs while updating the width of ContentView through PanGestureRecognizer.](#20772) </details> ## Navigation - Shell: Add duplicate route validation for sibling elements by @SubhikshaSf4851 in #32296 <details> <summary>🔧 Fixes</summary> - [OnNavigatedTo is not called when navigating from a specific page](#14000) </details> ## Picker - Improved Unfocus support for Picker on Mac Catalyst by @kubaflo in #33127 <details> <summary>🔧 Fixes</summary> - [When using voiceover unable to access expanded list of project combo box: A11y_.NET maui_user can creat a tak_Screen reader](#30897) - [Task and Project controls are not accessible with keyboard:A11y_.NET maui_User can create a new task_Keyboard](#30891) </details> ## SafeArea - [iOS] SafeArea: Return Empty for non-ISafeAreaView views (opt-in model) by @praveenkumarkarunanithi in #33526 <details> <summary>🔧 Fixes</summary> - [[iOS] SafeArea is not applied when a ContentPage uses a ControlTemplate](#33458) </details> ## Shell - [iOS] Fix ObjectDisposedException in TraitCollectionDidChange on window disposal by @jeremy-visionaid in #33353 <details> <summary>🔧 Fixes</summary> - [Intermittent crash on exit on MacCatalyst - ObjectDisposedException](#33352) </details> - [Issue-Resolver] Explicit fallback for BackButtonBehavior lookup by @kubaflo in #33204 <details> <summary>🔧 Fixes</summary> - [Setting BackButtonBehavior to not visible or not enabled does not work](#28570) - [BackButtonBehavior not bound](#33139) </details> ## Templates - [Templates] Remove redundant SemanticProperties.Description attribute by @kubaflo in #33621 <details> <summary>🔧 Fixes</summary> - [Task and Project controls are not accessible with keyboard:A11y_.NET maui_User can create a new task_Keyboard](#30891) - [Unable to select "Tags" when Voiceover is turned on.: A11y_Developer balance version .NET 10_Project_ScreenReader](#30749) </details> ## Theme - [Windows] Fix runtime theme update for controls and TitleBar by @Tamilarasan-Paranthaman in #31714 <details> <summary>🔧 Fixes</summary> - [[Windows][MacOS?] Change title bar color when switching light/dark theme at runtime](#12507) - [OS system components ignore app theme](#22058) - [[Mac Catalyst][Windows] TitleBar not reacting on UserAppTheme changes](#30518) - [In dark theme "Back" and "hamburger" button icon color contrast with background color is less than 3:1: A11y_.NET maui_User can get all the insights of Dashboard_Non text Contrast](#30807) - [`Switch` is invisible on `PointOver` when theme has changed](#31819) </details> ## Theming - [XSG] Fix Style Setters referencing source-generated bindable properties by @simonrozsival in #33562 ## Titlebar - [Windows] Fix TitleBar.IsVisible = false the caption buttons become unresponsive by @devanathan-vaithiyanathan in #33256 <details> <summary>🔧 Fixes</summary> - [When TitleBar.IsVisible = false the caption buttons become unresponsive on Windows](#33171) </details> ## WebView - Fix WebView JavaScript string escaping for backslashes and quotes by @StephaneDelcroix in #33726 ## Xaml - [XSG] Fix NaN value in XAML generating invalid code by @StephaneDelcroix in #33533 <details> <summary>🔧 Fixes</summary> - [[XSG] NaN value in XAML generates invalid code](#33532) </details> <details> <summary>📦 Other (1)</summary> - Remove InternalsVisibleTo attributes for .NET MAUI Community Toolkit by @jfversluis via @Copilot in #33442 </details> **Full Changelog**: main...inflight/candidate
Issue Details
On iOS 26, DisplayPromptAsync ignores the maxLength parameter, allowing users to enter an unlimited number of characters beyond the specified limit.
Root Cause
iOS 26 introduced a new delegate method, ShouldChangeCharactersInRanges, which accepts multiple text ranges instead of the older ShouldChangeCharacters method. On iOS 26, the old delegate is no longer invoked, causing MAUI’s maxLength enforcement to break.
Description of Change
A runtime version check was added to use the ShouldChangeCharactersInRanges delegate on iOS 26 and later, and the ShouldChangeCharacters delegate on earlier iOS versions. The new delegate calculates the total text length by summing all range lengths and validating the result against maxLength.
Validated the behavior in the following platforms
Issues Fixed
Fixes #33549
Test case
In the test for DisplayPromptAsync, there is no supported way to type text into the display prompt text fields using Appium.
Output ScreenShot
33549-BeforeFix.mov
33549-AfterFix.mov