Skip to content

Commit 90a57f5

Browse files
SubhikshaSf4851rmarinho
authored andcommitted
[Android & iOS] Fix for SearchHandler Character Spacing Property (#29497)
* [Android & iOS] Fix for character spacing in searchHandler * Updated test sample concerns * Update on naming * Update on formatting * Allowing updating character spacing to zero * Updated Andorid, iOS, Mac images
1 parent ceda3bd commit 90a57f5

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/Android/SearchHandlerAppearanceTracker.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public SearchHandlerAppearanceTracker(IShellSearchView searchView, IShellContext
3838
UpdateHorizontalTextAlignment();
3939
UpdateVerticalTextAlignment();
4040
UpdateInputType();
41+
UpdateCharacterSpacing();
4142
}
4243

4344
protected virtual void SearchHandlerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -90,6 +91,17 @@ protected virtual void SearchHandlerPropertyChanged(object sender, System.Compon
9091
{
9192
UpdateText();
9293
}
94+
else if (e.Is(SearchHandler.CharacterSpacingProperty))
95+
{
96+
UpdateCharacterSpacing();
97+
}
98+
}
99+
void UpdateCharacterSpacing()
100+
{
101+
if (_editText is not null)
102+
{
103+
_editText.LetterSpacing = _searchHandler.CharacterSpacing.ToEm();
104+
}
93105
}
94106

95107
void UpdateText()

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ void SearchHandlerPropertyChanged(object sender, System.ComponentModel.PropertyC
119119
{
120120
UpdateText(_uiSearchBar.FindDescendantView<UITextField>());
121121
}
122+
else if (e.Is(SearchHandler.CharacterSpacingProperty))
123+
{
124+
UpdateCharacterSpacing(_uiSearchBar.FindDescendantView<UITextField>());
125+
}
122126
}
123127

124128
void UpdateText(UITextField uiTextField)
@@ -128,6 +132,27 @@ void UpdateText(UITextField uiTextField)
128132

129133
uiTextField.Text = _searchHandler.Query;
130134
UpdateTextTransform(uiTextField);
135+
UpdateCharacterSpacing(uiTextField);
136+
}
137+
138+
void UpdateCharacterSpacing(UITextField textField)
139+
{
140+
if (textField is null)
141+
{
142+
return;
143+
}
144+
145+
var attributedText = textField.AttributedText?.WithCharacterSpacing(_searchHandler.CharacterSpacing);
146+
if (attributedText is not null)
147+
{
148+
textField.AttributedText = attributedText;
149+
}
150+
151+
var placeholderAttributedText = textField.AttributedPlaceholder?.WithCharacterSpacing(_searchHandler.CharacterSpacing);
152+
if (placeholderAttributedText is not null)
153+
{
154+
textField.AttributedPlaceholder = placeholderAttributedText;
155+
}
131156
}
132157

133158
void GetDefaultSearchBarColors(UISearchBar searchBar)
20.6 KB
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, "29492", "CharacterSpacing should be applied", PlatformAffected.Android | PlatformAffected.iOS)]
4+
public class Issue29492 : TestShell
5+
{
6+
protected override void Init()
7+
{
8+
var shellContent = new ShellContent
9+
{
10+
Title = "Home",
11+
Content = new Issue29492ContentPage() { Title = "Home" }
12+
};
13+
14+
Items.Add(shellContent);
15+
}
16+
17+
class Issue29492ContentPage : ContentPage
18+
{
19+
public Issue29492ContentPage()
20+
{
21+
var searchHandler = new SearchHandler
22+
{
23+
CharacterSpacing = 10
24+
};
25+
26+
var button = new Button
27+
{
28+
Text = "Enter Text",
29+
AutomationId = "Entertext",
30+
HorizontalOptions = LayoutOptions.Center,
31+
VerticalOptions = LayoutOptions.Center,
32+
};
33+
34+
button.Clicked += (s, e) =>
35+
{
36+
searchHandler.Query = "Hello World";
37+
};
38+
39+
Shell.SetSearchHandler(this, searchHandler);
40+
41+
Content = button;
42+
}
43+
}
44+
}
8.45 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if TEST_FAILS_ON_WINDOWS // Windows Character Spacing Issue Link - https://github.com/dotnet/maui/issues/29493
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
public class Issue29492 : _IssuesUITest
8+
{
9+
public Issue29492(TestDevice device)
10+
: base(device)
11+
{
12+
}
13+
14+
public override string Issue => "CharacterSpacing should be applied";
15+
16+
[Test]
17+
[Category(UITestCategories.Shell)]
18+
public void CharacterSpacingShouldApply()
19+
{
20+
App.WaitForElement("Entertext");
21+
App.Tap("Entertext");
22+
VerifyScreenshot();
23+
}
24+
}
25+
#endif
26.2 KB
Loading

0 commit comments

Comments
 (0)