-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS 26] - The MaxLength property value is not respected on an Entry control - fix #32045
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
base: net10.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -136,7 +136,11 @@ public void Connect(IEntry virtualView, MauiTextField platformView) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.EditingChanged += OnEditingChanged; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.EditingDidEnd += OnEditingEnded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.TextPropertySet += OnTextPropertySet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if IOS26_0_OR_GREATER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.ShouldChangeCharactersInRanges += ShouldChangeCharactersInRanges; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.ShouldChangeCharacters += OnShouldChangeCharacters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void Disconnect(MauiTextField platformView) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -148,7 +152,11 @@ public void Disconnect(MauiTextField platformView) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.EditingChanged -= OnEditingChanged; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.EditingDidEnd -= OnEditingEnded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.TextPropertySet -= OnTextPropertySet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if IOS26_0_OR_GREATER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.ShouldChangeCharactersInRanges -= ShouldChangeCharactersInRanges; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.ShouldChangeCharacters -= OnShouldChangeCharacters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (_set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| platformView.SelectionChanged -= OnSelectionChanged; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -213,8 +221,18 @@ void OnTextPropertySet(object? sender, EventArgs e) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if IOS26_0_OR_GREATER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool ShouldChangeCharactersInRanges(UITextField textField, NSValue[] ranges, string replacementString) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ranges is { Length: > 0 }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return VirtualView?.TextWithinMaxLength(textField.Text, ranges[0].RangeValue, replacementString) ?? false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+228
to
+229
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return VirtualView?.TextWithinMaxLength(textField.Text, ranges[0].RangeValue, replacementString) ?? false; | |
| { | |
| // Apply all ranges to the text to simulate the final result | |
| string originalText = textField.Text ?? string.Empty; | |
| var textChars = originalText.ToCharArray(); | |
| var resultText = originalText; | |
| // If multiple ranges, apply them in order | |
| // iOS passes the replacement string for all ranges, so we apply the replacement string to each range | |
| // To avoid index shifting, process ranges in reverse order | |
| var sortedRanges = ranges.Select(r => r.RangeValue).OrderByDescending(r => r.Location).ToArray(); | |
| foreach (var range in sortedRanges) | |
| { | |
| resultText = resultText.Remove((int)range.Location, (int)range.Length) | |
| .Insert((int)range.Location, replacementString); | |
| } | |
| // Now check if the result is within max length | |
| return VirtualView?.TextWithinMaxLength(resultText, new Foundation.NSRange(0, resultText.Length), string.Empty) ?? false; | |
| } |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Two separate methods duplicate MaxLength enforcement logic with different parameter shapes. Consider extracting a shared helper that computes the prospective text (supporting single or multiple ranges) to reduce duplication and ensure consistent behavior across iOS versions.
| if (ranges is { Length: > 0 }) | |
| return VirtualView?.TextWithinMaxLength(textField.Text, ranges[0].RangeValue, replacementString) ?? false; | |
| return true; | |
| } | |
| #else | |
| bool OnShouldChangeCharacters(UITextField textField, NSRange range, string replacementString) => | |
| VirtualView?.TextWithinMaxLength(textField.Text, range, replacementString) ?? false; | |
| #endif | |
| return IsTextWithinMaxLength(textField.Text, replacementString, ranges); | |
| } | |
| #else | |
| bool OnShouldChangeCharacters(UITextField textField, NSRange range, string replacementString) => | |
| IsTextWithinMaxLength(textField.Text, replacementString, range); | |
| #endif | |
| /// <summary> | |
| /// Helper to compute the prospective text after replacement and check MaxLength. | |
| /// Supports both single and multiple ranges. | |
| /// </summary> | |
| bool IsTextWithinMaxLength(string currentText, string replacementString, params object[] ranges) | |
| { | |
| if (VirtualView == null) | |
| return false; | |
| string prospectiveText = currentText; | |
| if (ranges.Length == 1 && ranges[0] is NSRange singleRange) | |
| { | |
| prospectiveText = ReplaceTextInRange(currentText, singleRange, replacementString); | |
| } | |
| else if (ranges.Length > 0 && ranges[0] is NSValue) | |
| { | |
| // Multiple ranges (iOS 16+) | |
| foreach (var obj in ranges) | |
| { | |
| if (obj is NSValue val) | |
| { | |
| var range = val.RangeValue; | |
| prospectiveText = ReplaceTextInRange(prospectiveText, range, replacementString); | |
| } | |
| } | |
| } | |
| return VirtualView.MaxLength <= 0 || prospectiveText.Length <= VirtualView.MaxLength; | |
| } | |
| /// <summary> | |
| /// Helper to replace text in a given NSRange. | |
| /// </summary> | |
| string ReplaceTextInRange(string text, NSRange range, string replacement) | |
| { | |
| if (range.Location > text.Length) | |
| return text; | |
| int start = (int)range.Location; | |
| int length = (int)range.Length; | |
| if (start + length > text.Length) | |
| length = text.Length - start; | |
| return text.Substring(0, start) + replacement + text.Substring(start + length); | |
| } |
Copilot
AI
Oct 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Two separate methods duplicate MaxLength enforcement logic with different parameter shapes. Consider extracting a shared helper that computes the prospective text (supporting single or multiple ranges) to reduce duplication and ensure consistent behavior across iOS versions.
| if (ranges is { Length: > 0 }) | |
| return VirtualView?.TextWithinMaxLength(textField.Text, ranges[0].RangeValue, replacementString) ?? false; | |
| return true; | |
| } | |
| #else | |
| bool OnShouldChangeCharacters(UITextField textField, NSRange range, string replacementString) => | |
| VirtualView?.TextWithinMaxLength(textField.Text, range, replacementString) ?? false; | |
| #endif | |
| var prospectiveText = ComputeProspectiveText(textField.Text, ranges, replacementString); | |
| return VirtualView?.TextWithinMaxLength(prospectiveText) ?? false; | |
| } | |
| #else | |
| bool OnShouldChangeCharacters(UITextField textField, NSRange range, string replacementString) | |
| { | |
| var prospectiveText = ComputeProspectiveText(textField.Text, range, replacementString); | |
| return VirtualView?.TextWithinMaxLength(prospectiveText) ?? false; | |
| } | |
| #endif | |
| /// <summary> | |
| /// Computes the prospective text after applying the replacement string to the given ranges. | |
| /// </summary> | |
| string ComputeProspectiveText(string currentText, NSValue[] ranges, string replacementString) | |
| { | |
| if (ranges == null || ranges.Length == 0) | |
| return currentText; | |
| // For iOS 26+, multiple ranges can be replaced at once. | |
| var text = currentText; | |
| foreach (var rangeValue in ranges) | |
| { | |
| var range = rangeValue.RangeValue; | |
| text = text.Remove((int)range.Location, (int)range.Length) | |
| .Insert((int)range.Location, replacementString); | |
| } | |
| return text; | |
| } | |
| /// <summary> | |
| /// Computes the prospective text after applying the replacement string to the given range. | |
| /// </summary> | |
| string ComputeProspectiveText(string currentText, NSRange range, string replacementString) | |
| { | |
| if (range.Length == 0) | |
| return currentText.Insert((int)range.Location, replacementString); | |
| return currentText.Remove((int)range.Location, (int)range.Length) | |
| .Insert((int)range.Location, replacementString); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New multi-range input handling lacks associated UI and shared tests to validate MaxLength enforcement when multiple selections/ranges are modified (e.g., batch deletes or multi-cursor replacements). Please add a HostApp issue page exercising multiple-range edits and a corresponding TestCases.Shared.Tests UITest to ensure behavior matches expectations.