iOS: Color of Editor Placeholder is different than Entry (#5259) fixes #5252

This commit is contained in:
Andrei Nitescu 2019-03-14 13:18:00 +02:00 коммит произвёл Rui Marinho
Родитель 07ada19a7d
Коммит 68652b9f10
3 изменённых файлов: 57 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,49 @@
using System.Linq;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 5252, "iOS: The Editor and Entry placeholder default color should be the same", PlatformAffected.iOS)]
class Issue5252 : TestContentPage
{
protected override void Init()
{
var sl = new StackLayout();
sl.Children.Add(new Label()
{
Text = "iOS: The Editor and Entry placeholder default color should be the same for consistency"
});
var entry = new Entry()
{
Placeholder = "Entry placeholder",
};
sl.Children.Add(entry);
var editor = new Editor()
{
Placeholder = "Editor placeholder",
};
sl.Children.Add(editor);
sl.Children.Add(new Button()
{
Text = "Toggle placeholder color",
Command = new Command(() =>
{
entry.PlaceholderColor = entry.PlaceholderColor.IsDefault ? Color.Red : (Color)Entry.PlaceholderColorProperty.DefaultValue;
editor.PlaceholderColor = editor.PlaceholderColor.IsDefault ? Color.Red : (Color)Editor.PlaceholderColorProperty.DefaultValue;
})
});
Content = new ScrollView()
{
Content = sl
};
}
}
}

Просмотреть файл

@ -430,6 +430,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue4600.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5252.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue5057.xaml.cs">
<DependentUpon>Issue5057.xaml</DependentUpon>
<SubType>Code</SubType>

Просмотреть файл

@ -9,6 +9,9 @@ namespace Xamarin.Forms.Platform.iOS
{
public class EditorRenderer : EditorRendererBase<UITextView>
{
// Using same placeholder color as for the Entry
readonly UIColor _defaultPlaceholderColor = ColorExtensions.SeventyPercentGrey;
UILabel _placeholderLabel;
public EditorRenderer()
@ -63,10 +66,11 @@ namespace Xamarin.Forms.Platform.iOS
protected internal override void UpdatePlaceholderColor()
{
if (Element.PlaceholderColor == Color.Default)
_placeholderLabel.TextColor = UIColor.DarkGray;
Color placeholderColor = Element.PlaceholderColor;
if (placeholderColor.IsDefault)
_placeholderLabel.TextColor = _defaultPlaceholderColor;
else
_placeholderLabel.TextColor = Element.PlaceholderColor.ToUIColor();
_placeholderLabel.TextColor = placeholderColor.ToUIColor();
}
void CreatePlaceholderLabel()