Skip to content

Commit

Permalink
iOS: Color of Editor Placeholder is different than Entry (xamarin#5259)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreinitescu authored and codemillmatt committed Apr 18, 2019
1 parent 7609412 commit 557d7c2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
@@ -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
};
}
}
}
Expand Up @@ -445,6 +445,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>
Expand Down
10 changes: 7 additions & 3 deletions Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
Expand Up @@ -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()
Expand Down Expand Up @@ -63,10 +66,11 @@ protected internal override void UpdatePlaceholderText()

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()
Expand Down

0 comments on commit 557d7c2

Please sign in to comment.