forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Wire up text for SearchBar and Editor (dotnet#2454)
* Wire up text for SearchBar and Editor * - searchbar * - fix searchbar text update * - convert to MauiSearchBar * Update EditorHandlerTests.cs * Update EditorHandlerTests.cs * Update EntryHandlerTests.cs * Update SearchBarHandler.iOS.cs * - fix Editor on iOS * Update EditorHandler.iOS.cs
- Loading branch information
Showing
23 changed files
with
300 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
namespace Microsoft.Maui | ||
{ | ||
public static class ITextInputExtensions | ||
{ | ||
public static void UpdateText(this ITextInput textInput, string? text) | ||
{ | ||
// Even though <null> is technically different to "", it has no | ||
// functional difference to apps. Thus, hide it. | ||
var mauiText = textInput.Text ?? string.Empty; | ||
var nativeText = text ?? string.Empty; | ||
if (mauiText != nativeText) | ||
textInput.Text = nativeText; | ||
} | ||
|
||
#if __ANDROID__ | ||
public static void UpdateText(this ITextInput textInput, Android.Text.TextChangedEventArgs e) | ||
{ | ||
if (e.BeforeCount == 0 && e.AfterCount == 0) | ||
return; | ||
|
||
if (e.Text is Java.Lang.ICharSequence cs) | ||
textInput.UpdateText(cs.ToString()); | ||
else if (e.Text != null) | ||
textInput.UpdateText(String.Concat(e.Text)); | ||
else | ||
textInput.UpdateText((string?)null); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Drawing; | ||
using CoreGraphics; | ||
using Foundation; | ||
using UIKit; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public class MauiSearchBar : UISearchBar | ||
{ | ||
public MauiSearchBar() : this(RectangleF.Empty) | ||
{ | ||
} | ||
|
||
public MauiSearchBar(NSCoder coder) : base(coder) | ||
{ | ||
} | ||
|
||
public MauiSearchBar(CGRect frame) : base(frame) | ||
{ | ||
} | ||
|
||
protected MauiSearchBar(NSObjectFlag t) : base(t) | ||
{ | ||
} | ||
|
||
protected internal MauiSearchBar(IntPtr handle) : base(handle) | ||
{ | ||
} | ||
|
||
public override string? Text | ||
{ | ||
get => base.Text; | ||
set | ||
{ | ||
var old = base.Text; | ||
|
||
base.Text = value; | ||
|
||
if (old != value) | ||
TextPropertySet?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
|
||
public event EventHandler? TextPropertySet; | ||
} | ||
} |
Oops, something went wrong.