Skip to content

Commit

Permalink
feat(TextBox): iOS selection and placeholder color
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Sep 16, 2022
1 parent 14854a7 commit e1494e2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface ITextBoxView : ITextInput
#if __IOS__
bool IsFirstResponder { get; }
void UpdateTextAlignment();
UIColor TintColor { get; set; }
#endif

Brush Foreground { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public void OnForegroundChanged(Brush oldValue, Brush newValue)
void ApplyColor()
{
this.TextColor = scb.Color;
this.TintColor = scb.Color;
}
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,11 @@ private void UpdateInputScope(InputScope inputScope)
}
}

partial void OnSelectionHighlightColorChangedPartial(Color? selectionHighlightColor)
partial void OnSelectionHighlightColorChangedPartial(Color color)
{
if (_textBoxView != null)
{
if (selectionHighlightColor != null)
{
var windowsColor = selectionHighlightColor.Value;
_textBoxView.SetHighlightColor(new Android.Graphics.Color(windowsColor.R, windowsColor.G, windowsColor.B, windowsColor.A));
}
else
{
int[] attrs = { Android.Resource.Attribute.TextColorHighlight };
TypedArray ta = ContextHelper.Current.ObtainStyledAttributes(attrs);
int colorInt = ta.GetResourceId(0, Android.Resource.Color.Black);
ta.Recycle();
var color = new Android.Graphics.Color(colorInt);
_textBoxView.SetHighlightColor(color);
}
_textBoxView.SetHighlightColor(new Android.Graphics.Color(color.R, color.G, color.B, color.A));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,13 @@ public SolidColorBrush SelectionHighlightColor

private void OnSelectionHighlightColorChanged(DependencyPropertyChangedEventArgs e)
{
var value = e.NewValue as SolidColorBrush;
OnSelectionHighlightColorChangedPartial(value?.ColorWithOpacity);
if (e.NewValue is SolidColorBrush brush)
{
OnSelectionHighlightColorChangedPartial(brush.ColorWithOpacity);
}
}

partial void OnSelectionHighlightColorChangedPartial(Color? e);
partial void OnSelectionHighlightColorChangedPartial(Color color);

#endregion

Expand Down
8 changes: 8 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ partial void OnIsReadonlyChangedPartial(DependencyPropertyChangedEventArgs e)
//support by MultilineTextBoxDelegate and SinglelineTextBoxDelegate
}

partial void OnSelectionHighlightColorChangedPartial(Color color)
{
if (_textBoxView != null)
{
_textBoxView.TintColor = UIColor.FromRGBA(color.R, color.G, color.B, color.A);
}
}

partial void OnIsSpellCheckEnabledChangedPartial(DependencyPropertyChangedEventArgs e)
{
if (_textBoxView != null)
Expand Down

0 comments on commit e1494e2

Please sign in to comment.