[iOS] Check new element before creating placeholder label (#5432)

* Check new element before creating placeholder label

* additional checks

* create placeholder once
This commit is contained in:
E.Z. Hart 2019-03-05 11:06:27 -07:00 коммит произвёл Samantha Houts
Родитель 21c7567e02
Коммит a372395fb2
1 изменённых файлов: 16 добавлений и 5 удалений

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

@ -31,15 +31,23 @@ namespace Xamarin.Forms.Platform.iOS
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{ {
// create label so it can get updated during the initial setup loop bool initializing = false;
_placeholderLabel = new UILabel if (e.NewElement != null && _placeholderLabel == null)
{ {
BackgroundColor = UIColor.Clear initializing = true;
}; // create label so it can get updated during the initial setup loop
_placeholderLabel = new UILabel
{
BackgroundColor = UIColor.Clear
};
}
base.OnElementChanged(e); base.OnElementChanged(e);
CreatePlaceholderLabel(); if (e.NewElement != null && initializing)
{
CreatePlaceholderLabel();
}
} }
protected internal override void UpdateFont() protected internal override void UpdateFont()
@ -63,6 +71,9 @@ namespace Xamarin.Forms.Platform.iOS
void CreatePlaceholderLabel() void CreatePlaceholderLabel()
{ {
if (Control == null)
return;
Control.AddSubview(_placeholderLabel); Control.AddSubview(_placeholderLabel);
var edgeInsets = TextView.TextContainerInset; var edgeInsets = TextView.TextContainerInset;