Skip to content

Commit

Permalink
[iOS]Fix for Character Spacing Not Updating Correctly in Editor for D…
Browse files Browse the repository at this point in the history
…ynamically Added Text (#25347)

* fix and UI test added

* review changes added

* WinUI snap added

* fix and UI test added

* review changes added

* WinUI snap added

* fail on mac removed

* modified a test case

* Removed-TestCases-Failure-Snap

* Modified-TestCases

* Added-KeyBoard-Hide-Function.

* Added-SnapShots

* Added-iOS-SnapShot

* Updated-Android-SnapShot

* Revert "Fixed CollectionViewHandler2 null reference exception if ItemsLayout is set for Tablet but not on mobile devices (#26152)"

This reverts commit 0ddc794.

* Reapply "Fixed CollectionViewHandler2 null reference exception if ItemsLayout is set for Tablet but not on mobile devices (#26152)"

This reverts commit 4b9074c.

* Removed-Mac-TestCase-Failing-Code

* Added-Mac-Snapshot

---------

Co-authored-by: Prakash Kannan <prakash.kannan@syncfusion.com>
Co-authored-by: prakashKannanSf3972 <127308739+prakashKannanSf3972@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent b2654b2 commit 664caaf
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Controls/src/Core/Editor/Editor.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public static void MapText(EditorHandler handler, Editor editor) =>
public static void MapText(IEditorHandler handler, Editor editor)
{
Platform.TextExtensions.UpdateText(handler.PlatformView, editor);

// Any text changes in the editor field require recalculating the CharacterSpacing by regenerating the attributed string to properly apply the spacing and override the current text formatting.
handler?.UpdateValue(nameof(CharacterSpacing));
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue17782.xaml
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>
39 changes: 39 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue17782.xaml.cs
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();
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 664caaf

Please sign in to comment.