--- /dev/null
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 51825, "[iOS] Korean input in SearchBar doesn't work", PlatformAffected.iOS)]
+ public class Bugzilla51815 : TestContentPage
+ {
+ protected override void Init()
+ {
+ var sb = new SearchBar { AutomationId = "Bugzilla51825SearchBar" };
+ var text = new Label { AutomationId = "Bugzilla51825Label" };
+ sb.TextChanged += (sender, e) =>
+ {
+ text.Text = sb.Text;
+ };
+
+ Content = new StackLayout
+ {
+ Children =
+ {
+ sb,
+ new Button
+ {
+ AutomationId = "Bugzilla51825Button",
+ Text = "Change SearchBar text",
+ Command = new Command(() =>
+ {
+ sb.Text = "Test";
+ })
+ },
+ text,
+ new Label
+ {
+ Text = "The label above should match the text in the SearchBar; " +
+ "additionally, typing Korean characters should properly combine them."
+ }
+ }
+ };
+ }
+
+#if UITEST
+ [Test]
+ public void Bugzilla51825Test ()
+ {
+ RunningApp.WaitForElement (q => q.Marked ("Bugzilla51825SearchBar"));
+ RunningApp.EnterText(q => q.Marked("Bugzilla51825SearchBar"), "Hello");
+ var entry = RunningApp.Query(q => q.Marked("Bugzilla51825Label"))[0];
+ Assert.AreEqual("Hello", entry.Text);
+ RunningApp.Tap("Bugzilla51825Button");
+ entry = RunningApp.Query(q => q.Marked("Bugzilla51825Label"))[0];
+ Assert.AreEqual("Test", entry.Text);
+ }
+#endif
+ }
+}
\ No newline at end of file
UIColor _defaultTextColor;
UIColor _defaultTintColor;
UITextField _textField;
+ bool _textWasTyped;
+ string _typedText;
IElementController ElementController => Element as IElementController;
void OnTextChanged(object sender, UISearchBarTextChangedEventArgs a)
{
- ElementController.SetValueFromRenderer(SearchBar.TextProperty, Control.Text);
+ // This only fires when text has been typed into the SearchBar; see UpdateText()
+ // for why this is handled in this manner.
+ _textWasTyped = true;
+ _typedText = a.SearchText;
+ UpdateOnTextChanged();
}
void UpdateAlignment()
void UpdateText()
{
- Control.Text = Element.Text;
+ // There is at least one scenario where modifying the Element's Text value from TextChanged
+ // can cause issues with a Korean keyboard. The characters normally combine into larger
+ // characters as they are typed, but if SetValueFromRenderer is used in that manner,
+ // it ignores the combination and outputs them individually. This hook only fires
+ // when typing, so by keeping track of whether or not text was typed, we can respect
+ // other changes to Element.Text.
+ if (!_textWasTyped)
+ Control.Text = Element.Text;
+
UpdateCancelButton();
}
+ void UpdateOnTextChanged()
+ {
+ ElementController?.SetValueFromRenderer(SearchBar.TextProperty, _typedText);
+ _textWasTyped = false;
+ }
+
void UpdateTextColor()
{
_textField = _textField ?? Control.FindDescendantView<UITextField>();