Skip to content
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

Switch Entry and Editor from EditText to AppCompatEditText #493

Merged
merged 6 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Core/src/Handlers/Editor/EditorHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.AppCompat.Widget;

namespace Microsoft.Maui.Handlers
{
public partial class EditorHandler : AbstractViewHandler<IEditor, EditText>
public partial class EditorHandler : AbstractViewHandler<IEditor, AppCompatEditText>
{
protected override EditText CreateNativeView()
protected override AppCompatEditText CreateNativeView()
{
var editText = new EditText(Context)
var editText = new AppCompatEditText(Context)
{
ImeOptions = ImeAction.Done
};
Expand Down
14 changes: 7 additions & 7 deletions src/Core/src/Handlers/Entry/EntryHandler.Android.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using Android.Content.Res;
using Android.Text;
using Android.Widget;
using AndroidX.AppCompat.Widget;

namespace Microsoft.Maui.Handlers
{
public partial class EntryHandler : AbstractViewHandler<IEntry, EditText>
public partial class EntryHandler : AbstractViewHandler<IEntry, AppCompatEditText>
{
TextWatcher Watcher { get; } = new TextWatcher();

static ColorStateList? DefaultTextColors { get; set; }

protected override EditText CreateNativeView()
protected override AppCompatEditText CreateNativeView()
{
return new EditText(Context);
return new AppCompatEditText(Context);
}

protected override void ConnectHandler(EditText nativeView)
protected override void ConnectHandler(AppCompatEditText nativeView)
{
Watcher.Handler = this;
nativeView.AddTextChangedListener(Watcher);
}

protected override void DisconnectHandler(EditText nativeView)
protected override void DisconnectHandler(AppCompatEditText nativeView)
{
nativeView.RemoveTextChangedListener(Watcher);
Watcher.Handler = null;
}

protected override void SetupDefaults(EditText nativeView)
protected override void SetupDefaults(AppCompatEditText nativeView)
{
base.SetupDefaults(nativeView);
DefaultTextColors = nativeView.TextColors;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Platform/Android/EditorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Android.Widget;
using AndroidX.AppCompat.Widget;

namespace Microsoft.Maui
{
public static class EditorExtensions
{
public static void UpdateText(this EditText editText, IEditor editor)
public static void UpdateText(this AppCompatEditText editText, IEditor editor)
{
string text = editor.Text;

Expand Down
16 changes: 8 additions & 8 deletions src/Core/src/Platform/Android/EntryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Android.Content.Res;
using Android.Text;
using Android.Widget;
using AndroidX.AppCompat.Widget;

namespace Microsoft.Maui
{
Expand All @@ -11,7 +11,7 @@ public static class EntryExtensions
new[] { -global::Android.Resource.Attribute.StateEnabled }
};

public static void UpdateText(this EditText editText, IEntry entry)
public static void UpdateText(this AppCompatEditText editText, IEntry entry)
{
var newText = entry.Text ?? string.Empty;
var oldText = editText.Text ?? string.Empty;
Expand All @@ -20,7 +20,7 @@ public static void UpdateText(this EditText editText, IEntry entry)
editText.Text = newText;
}

public static void UpdateTextColor(this EditText editText, IEntry entry, ColorStateList? defaultColor)
public static void UpdateTextColor(this AppCompatEditText editText, IEntry entry, ColorStateList? defaultColor)
{
var textColor = entry.TextColor;
if (textColor.IsDefault)
Expand All @@ -39,12 +39,12 @@ public static void UpdateTextColor(this EditText editText, IEntry entry, ColorSt
}
}

public static void UpdateIsPassword(this EditText editText, IEntry entry)
public static void UpdateIsPassword(this AppCompatEditText editText, IEntry entry)
{
editText.SetInputType(entry);
}

internal static void SetInputType(this EditText editText, IEntry entry)
internal static void SetInputType(this AppCompatEditText editText, IEntry entry)
{
editText.InputType = InputTypes.ClassText;
editText.InputType |= InputTypes.TextFlagMultiLine;
Expand All @@ -62,20 +62,20 @@ internal static void SetInputType(this EditText editText, IEntry entry)
editText.InputType = InputTypes.Null;
}

public static void UpdateIsTextPredictionEnabled(this EditText editText, IEntry entry)
public static void UpdateIsTextPredictionEnabled(this AppCompatEditText editText, IEntry entry)
{
editText.SetInputType(entry);
}

public static void UpdatePlaceholder(this EditText editText, IEntry entry)
public static void UpdatePlaceholder(this AppCompatEditText editText, IEntry entry)
{
if (editText.Hint == entry.Placeholder)
return;

editText.Hint = entry.Placeholder;
}

public static void UpdateIsReadOnly(this EditText editText, IEntry entry)
public static void UpdateIsReadOnly(this AppCompatEditText editText, IEntry entry)
{
bool isEditable = !entry.IsReadOnly;

Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Platform/iOS/EntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static void UpdateIsTextPredictionEnabled(this UITextField textField, IEn
textField.AutocorrectionType = UITextAutocorrectionType.No;
}

public static void UpdatePlaceholder(this UITextField editText, IEntry entry)
public static void UpdatePlaceholder(this UITextField textField, IEntry entry)
{
editText.Placeholder = entry.Placeholder;
textField.Placeholder = entry.Placeholder;
}

public static void UpdateIsReadOnly(this UITextField textField, IEntry entry)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Android.Text;
using Android.Widget;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Handlers;

namespace Microsoft.Maui.DeviceTests
{
public partial class EditorHandlerTests
{
EditText GetNativeEditor(EditorHandler editorHandler) =>
(EditText)editorHandler.View;
AppCompatEditText GetNativeEditor(EditorHandler editorHandler) =>
(AppCompatEditText)editorHandler.View;

string GetNativeText(EditorHandler editorHandler) =>
GetNativeEditor(editorHandler).Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Android.Text;
using Android.Widget;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Handlers;
using AColor = global::Android.Graphics.Color;

namespace Microsoft.Maui.DeviceTests
{
public partial class EntryHandlerTests
{
EditText GetNativeEntry(EntryHandler entryHandler) =>
(EditText)entryHandler.View;
AppCompatEditText GetNativeEntry(EntryHandler entryHandler) =>
(AppCompatEditText)entryHandler.View;

string GetNativeText(EntryHandler entryHandler) =>
GetNativeEntry(entryHandler).Text;
Expand Down