Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,79 @@ await InvokeOnMainThreadAsync(() =>
AssertTranslationMatches(nativeView, entry.TranslationX, entry.TranslationY);
});
}

[Fact]
[Category(TestCategory.Entry)]
public async Task KeyboardPasswordDoesNotForcePasswordVisibilityWhenIsPasswordFalse()
{
var entry = new Entry
{
Keyboard = Keyboard.Password,
IsPassword = false,
Text = "Password"
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var platformEntry = GetPlatformControl(handler);

await InvokeOnMainThreadAsync(() =>
{
Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationPassword));
Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.NumberVariationPassword));
});
}

[Fact]
[Category(TestCategory.Entry)]
public async Task KeyboardPasswordRespectsIsPasswordToggle()
{
var entry = new Entry
{
Keyboard = Keyboard.Password,
IsPassword = false,
Text = "Password"
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var platformEntry = GetPlatformControl(handler);

await InvokeOnMainThreadAsync(() =>
{
Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationPassword));

entry.IsPassword = true;
handler.UpdateValue(nameof(IEntry.IsPassword));

Assert.True(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationPassword));

entry.IsPassword = false;
handler.UpdateValue(nameof(IEntry.IsPassword));

Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationPassword));
Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.NumberVariationPassword));
});
}

[Fact]
[Category(TestCategory.Entry)]
public async Task KeyboardUrlPreservesUrlInputTypeWhenIsPasswordFalse()
{
var entry = new Entry
{
Keyboard = Keyboard.Url,
IsPassword = false,
Text = "https://dot.net"
};

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var platformEntry = GetPlatformControl(handler);

await InvokeOnMainThreadAsync(() =>
{
Assert.True(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.ClassText));
Assert.True(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationUri));
Assert.False(platformEntry.InputType.HasFlag(global::Android.Text.InputTypes.TextVariationPassword));
});
}
}
}
22 changes: 17 additions & 5 deletions src/Core/src/Platform/Android/EditTextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,24 @@ internal static void SetInputType(this EditText editText, ITextInput textInput)
editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType);
}

if (textInput is IEntry entry && entry.IsPassword)
if (textInput is IEntry entry)
{
if (editText.InputType.HasFlag(InputTypes.ClassText))
editText.InputType |= InputTypes.TextVariationPassword;
if (editText.InputType.HasFlag(InputTypes.ClassNumber))
editText.InputType |= InputTypes.NumberVariationPassword;
if (entry.IsPassword)
{
if (editText.InputType.HasFlag(InputTypes.ClassText))
editText.InputType |= InputTypes.TextVariationPassword;

if (editText.InputType.HasFlag(InputTypes.ClassNumber))
editText.InputType |= InputTypes.NumberVariationPassword;
}
else
{
if (editText.InputType.HasFlag(InputTypes.ClassText))
editText.InputType &= ~InputTypes.TextVariationPassword;

if (editText.InputType.HasFlag(InputTypes.ClassNumber))
editText.InputType &= ~InputTypes.NumberVariationPassword;
}
}

if (textInput is IEditor)
Expand Down
Loading