-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS]Fix for Character Spacing Not Updating Correctly in Editor for Dynamically Added Text #25347
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
Changes from 17 commits
eb2f05e
1f0634e
7d5e245
57d3160
9051718
71f1e97
e889545
08a9063
d32064a
903ca51
80c9ca7
11618d2
2c637bb
6003463
b0d9c0c
c464a59
f233d1f
4b9074c
92a1c94
53764a1
7666e57
19d79a6
01b9d40
fce9a9a
a78d07a
b9fa465
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue17782" | ||
| xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues" | ||
| Title="Issue 17782"> | ||
|
|
||
| <VerticalStackLayout x:Name="verticalStack" Spacing="10"> | ||
|
|
||
| <!-- Case 1: Add text to the editor with initial CharacterSpacing set to 10. | ||
| The Button click updates the text to a predefined value. --> | ||
| <Editor x:Name="initialCharacterSpacingEditor" | ||
| AutomationId="InitialCharacterSpacingEditor" | ||
| CharacterSpacing="10" | ||
| HeightRequest="60"/> | ||
|
|
||
| <Button x:Name="buttonAddEditorText" | ||
| AutomationId="ButtonAddEditorText" | ||
| Text="Click to Add Editor Text" | ||
| Clicked="OnAddEditorTextClicked" | ||
| HorizontalOptions="Fill" /> | ||
|
|
||
| <!-- Case 2: Update CharacterSpacing of the editor programmatically. | ||
| Initially, the CharacterSpacing is not set, and upon clicking the button, it is updated to 10. --> | ||
| <Editor x:Name="dynamicCharacterSpacingEditor" | ||
| AutomationId="DynamicCharacterSpacingEditor" | ||
| HeightRequest="60" /> | ||
|
|
||
| <Button x:Name="buttonUpdateCharacterSpacing" | ||
| AutomationId="ButtonUpdateCharacterSpacing" | ||
| Text="Update Dynamic Character Spacing" | ||
| Clicked="OnUpdateCharacterSpacingClicked" /> | ||
|
|
||
| <!-- Case 3: Reset CharacterSpacing of the editor to zero. | ||
| Initially, the CharacterSpacing is set to 10, and the Button click resets it to 0. --> | ||
| <Editor x:Name="resetCharacterSpacingEditor" | ||
| AutomationId="ResetCharacterSpacingEditor" | ||
| CharacterSpacing="10" | ||
| HeightRequest="60" /> | ||
|
|
||
| <Button x:Name="buttonResetCharacterSpacing" | ||
| AutomationId="ButtonResetCharacterSpacing" | ||
| Text="Reset Character Spacing" | ||
| Clicked="OnResetCharacterSpacingClicked" /> | ||
|
|
||
| <!-- Case 4: Bind CharacterSpacing of the editor to a Slider's value. | ||
| The Slider allows dynamic adjustment of the editor's CharacterSpacing in real-time. --> | ||
| <Editor x:Name="editorWithSlider" | ||
| AutomationId="EditorWithSlider" | ||
| Text="Editor" | ||
| CharacterSpacing="{Binding Value}" | ||
| BindingContext="{x:Reference Slider}" /> | ||
|
|
||
| <Slider x:Name="Slider" | ||
| AutomationId="SliderCharacterSpacing" | ||
| Minimum="0" | ||
| Maximum="30" | ||
| Value="10" /> | ||
|
|
||
| <Button AutomationId="EditorsUnfocusButton" | ||
| Text="Set Editors Unfocus" | ||
| Clicked="OnEditorsUnfocusButtonClicked" /> | ||
| </VerticalStackLayout> | ||
|
|
||
| </ContentPage> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System.Collections.ObjectModel; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
|
|
||
| [Issue(IssueTracker.Github, 17782, "[ManualMauiTests] New text in the Editor character spacing test sometimes uses the previous spacing", PlatformAffected.iOS)] | ||
| public partial class Issue17782 : ContentPage | ||
| { | ||
|
|
||
| public Issue17782() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| private void OnAddEditorTextClicked(object sender, EventArgs e) | ||
| { | ||
| initialCharacterSpacingEditor.Text = "Initial CharacterSpacing with Text"; | ||
| } | ||
|
|
||
| private void OnUpdateCharacterSpacingClicked(object sender, EventArgs e) | ||
| { | ||
| dynamicCharacterSpacingEditor.CharacterSpacing = 10; | ||
| } | ||
|
|
||
| private void OnResetCharacterSpacingClicked(object sender, EventArgs e) | ||
| { | ||
| resetCharacterSpacingEditor.CharacterSpacing = 0; | ||
| } | ||
|
|
||
| private void OnEditorsUnfocusButtonClicked(object sender, EventArgs e) | ||
| { | ||
| foreach(var child in verticalStack.Children) | ||
| { | ||
| if(child is Editor editor) | ||
| editor.Unfocus(); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #if !MACCATALYST | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue17782 : _IssuesUITest | ||
| { | ||
| public Issue17782(TestDevice testDevice) : base(testDevice) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "[ManualMauiTests] New text in the Editor character spacing test sometimes uses the previous spacing"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Editor)] | ||
| public void VerifyEditorCharacterSpacingWithText() | ||
| { | ||
| App.WaitForElement("SliderCharacterSpacing"); | ||
| App.Click("ButtonAddEditorText"); | ||
| App.Click("ButtonUpdateCharacterSpacing"); | ||
| App.EnterText("DynamicCharacterSpacingEditor", "Text"); | ||
| App.Click("ButtonResetCharacterSpacing"); | ||
| App.EnterText("ResetCharacterSpacingEditor", "Text"); | ||
| App.Click("EditorsUnfocusButton"); | ||
| #if IOS | ||
| App.DismissKeyboard(); | ||
| #endif | ||
| VerifyScreenshot(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback. We observed successful image generation during our testing. The discrepancies might stem from version differences between the emulator and simulator environments in CI.As per your suggestion added App.DismissKeyboard(). |
||
| } | ||
| } | ||
| #endif | ||

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.
The fix looks good but, trying to understand why is necessary because is something we already are doing.
In the EditorHandler, updating the Text property we are invoking the MapFormatting method:
maui/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs
Line 85 in f269ef3
Where update the CharacterSpacing after set the text:
maui/src/Core/src/Handlers/Editor/EditorHandler.iOS.cs
Line 138 in f269ef3
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.
@jsuarezruiz,
Since, we are remapping in editor text Property, which directly calls Editor.iOS MapText on text changes instead of MapText in EntryHandler.iOS. So, the MapText function in EntryHandler.iOS is not invoked whenever text changes.
Additionally, we’re already handling MaxLength in UpdateText, so there’s no need to update UpdateMaxLength through MapFormatting, as we ensure the length limitation within UpdateText itself. By doing this, the MapText method remains efficient and prevents unnecessary reprocessing, focusing solely on applying changes relevant to CharacterSpacing.
maui/src/Core/src/Core/Extensions/ITextInputExtensions.cs
Lines 18 to 19 in ad6f752