diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs index da7879c83..eeb643190 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs @@ -52,6 +52,20 @@ namespace Xamarin.Forms.Controls var xAlignPlaceholderStart = new ViewContainer (Test.Entry.HorizontalTextAlignmentPlaceholderStart, new Entry { Placeholder = "Should be aligned start", HorizontalTextAlignment = TextAlignment.Start }); + var yAlignCenterContainer = new ViewContainer(Test.Entry.VerticalTextAlignmentCenter, + new Entry { Text = "Should be centered!", VerticalTextAlignment = TextAlignment.Center, BackgroundColor = Color.Pink, HeightRequest = 100 }); + var yAlignEndContainer = new ViewContainer(Test.Entry.VerticalTextAlignmentEnd, + new Entry { Text = "Should be aligned end!", VerticalTextAlignment = TextAlignment.End, BackgroundColor = Color.Pink, HeightRequest = 100 }); + var yAlignStartContainer = new ViewContainer(Test.Entry.VerticalTextAlignmentStart, + new Entry { Text = "Should be aligned start!", VerticalTextAlignment = TextAlignment.Start, BackgroundColor = Color.Pink, HeightRequest = 100 }); + + var yAlignPlaceholderCenter = new ViewContainer(Test.Entry.VerticalTextAlignmentPlaceholderCenter, + new Entry { Placeholder = "Should be centered!", VerticalTextAlignment = TextAlignment.Center, BackgroundColor = Color.Pink, HeightRequest = 100 }); + var yAlignPlaceholderEnd = new ViewContainer(Test.Entry.VerticalTextAlignmentPlaceholderEnd, + new Entry { Placeholder = "Should be aligned end!", VerticalTextAlignment = TextAlignment.End, BackgroundColor = Color.Pink, HeightRequest = 100 }); + var yAlignPlaceholderStart = new ViewContainer(Test.Entry.VerticalTextAlignmentPlaceholderStart, + new Entry { Placeholder = "Should be aligned start!", VerticalTextAlignment = TextAlignment.Start, BackgroundColor = Color.Pink, HeightRequest = 100 }); + var placeholderColorContainer = new ViewContainer (Test.Entry.PlaceholderColor, new Entry { Placeholder = "Hi, I should be red", PlaceholderColor = Color.Red }); @@ -104,6 +118,12 @@ namespace Xamarin.Forms.Controls Add (xAlignEndContainer); Add (xAlignPlaceholderStart); Add (xAlignStartContainer); + Add (yAlignPlaceholderCenter); + Add (yAlignCenterContainer); + Add (yAlignPlaceholderEnd); + Add (yAlignEndContainer); + Add (yAlignPlaceholderStart); + Add (yAlignStartContainer); Add (textFontAttributesContainer); Add (textFamilyContainer1); Add (textFamilyContainer2); diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs index 8122c118f..e7d0c67b0 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs @@ -107,7 +107,8 @@ namespace Xamarin.Forms.Controls Text = "VerticalTextAlignment Start", VerticalTextAlignment = TextAlignment.Center, HeightRequest = alignmentTestsHeightRequest, - WidthRequest = alignmentTestsWidthRequest + WidthRequest = alignmentTestsWidthRequest, + BackgroundColor = Color.Pink } ); @@ -116,7 +117,8 @@ namespace Xamarin.Forms.Controls Text = "VerticalTextAlignment End", VerticalTextAlignment = TextAlignment.End, HeightRequest = alignmentTestsHeightRequest, - WidthRequest = alignmentTestsWidthRequest + WidthRequest = alignmentTestsWidthRequest, + BackgroundColor = Color.Pink } ); @@ -125,7 +127,8 @@ namespace Xamarin.Forms.Controls Text = "VerticalTextAlignment Start", VerticalTextAlignment = TextAlignment.Start, HeightRequest = alignmentTestsHeightRequest, - WidthRequest = alignmentTestsWidthRequest + WidthRequest = alignmentTestsWidthRequest, + BackgroundColor = Color.Pink } ); diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/SearchBarCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/SearchBarCoreGalleryPage.cs index 9a548cc6f..d1efa949b 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/SearchBarCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/SearchBarCoreGalleryPage.cs @@ -52,6 +52,13 @@ namespace Xamarin.Forms.Controls var textAlignmentEndContainer = new ViewContainer (Test.SearchBar.TextAlignmentEnd, new SearchBar { Text = "I should be at the end", HorizontalTextAlignment = TextAlignment.End }); + var textVerticalAlignmentStartContainer = new ViewContainer(Test.SearchBar.TextVerticalAlignmentStart, + new SearchBar { Text = "I should be at the start", VerticalTextAlignment = TextAlignment.Start }); + var textVerticalAlignmentCenterContainer = new ViewContainer(Test.SearchBar.TextVerticalAlignmentCenter, + new SearchBar { Text = "I should be centered", VerticalTextAlignment = TextAlignment.Center }); + var textVerticalAlignmentEndContainer = new ViewContainer(Test.SearchBar.TextVerticalAlignmentEnd, + new SearchBar { Text = "I should be at the end", VerticalTextAlignment = TextAlignment.End }); + var placeholderAlignmentStartContainer = new ViewContainer (Test.SearchBar.PlaceholderAlignmentStart, new SearchBar { Placeholder = "I should be at the start", HorizontalTextAlignment = TextAlignment.Start }); var placeholderAlignmentCenterContainer = new ViewContainer (Test.SearchBar.PlaceholderAlignmentCenter, @@ -59,6 +66,13 @@ namespace Xamarin.Forms.Controls var placeholderAlignmentEndContainer = new ViewContainer (Test.SearchBar.PlaceholderAlignmentEnd, new SearchBar { Placeholder = "I should be at the end", HorizontalTextAlignment = TextAlignment.End }); + var placeholderVerticalAlignmentStartContainer = new ViewContainer(Test.SearchBar.PlaceholderVerticalAlignmentStart, + new SearchBar { Placeholder = "I should be at the start", VerticalTextAlignment = TextAlignment.Start }); + var placeholderVerticalAlignmentCenterContainer = new ViewContainer(Test.SearchBar.PlaceholderVerticalAlignmentCenter, + new SearchBar { Placeholder = "I should be centered", VerticalTextAlignment = TextAlignment.Center }); + var placeholderVerticalAlignmentEndContainer = new ViewContainer(Test.SearchBar.PlaceholderVerticalAlignmentEnd, + new SearchBar { Placeholder = "I should be at the end", VerticalTextAlignment = TextAlignment.End }); + var textColorContainer = new ViewContainer (Test.SearchBar.TextColor, new SearchBar { Text = "I should be red", TextColor = Color.Red }); @@ -89,6 +103,12 @@ namespace Xamarin.Forms.Controls Add (placeholderAlignmentStartContainer); Add (placeholderAlignmentCenterContainer); Add (placeholderAlignmentEndContainer); + Add (textVerticalAlignmentStartContainer); + Add (textVerticalAlignmentCenterContainer); + Add (textVerticalAlignmentEndContainer); + Add (placeholderVerticalAlignmentStartContainer); + Add (placeholderVerticalAlignmentCenterContainer); + Add (placeholderVerticalAlignmentEndContainer); Add (textColorContainer); Add (placeholderColorContainer); Add (keyboardContainer); diff --git a/Xamarin.Forms.Core/Cells/EntryCell.cs b/Xamarin.Forms.Core/Cells/EntryCell.cs index 466baf7df..a87abdc8e 100644 --- a/Xamarin.Forms.Core/Cells/EntryCell.cs +++ b/Xamarin.Forms.Core/Cells/EntryCell.cs @@ -17,6 +17,8 @@ namespace Xamarin.Forms public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; + public static readonly BindableProperty VerticalTextAlignmentProperty = TextAlignmentElement.VerticalTextAlignmentProperty; + [Obsolete("XAlignProperty is obsolete as of version 2.0.0. Please use HorizontalTextAlignmentProperty instead.")] [EditorBrowsable(EditorBrowsableState.Never)] public static readonly BindableProperty XAlignProperty = HorizontalTextAlignmentProperty; @@ -27,6 +29,12 @@ namespace Xamarin.Forms set { SetValue(TextAlignmentElement.HorizontalTextAlignmentProperty, value); } } + public TextAlignment VerticalTextAlignment + { + get { return (TextAlignment)GetValue(TextAlignmentElement.VerticalTextAlignmentProperty); } + set { SetValue(TextAlignmentElement.VerticalTextAlignmentProperty, value); } + } + public Keyboard Keyboard { get { return (Keyboard)GetValue(KeyboardProperty); } diff --git a/Xamarin.Forms.Core/Entry.cs b/Xamarin.Forms.Core/Entry.cs index 6c97f9a45..228ebe5c8 100644 --- a/Xamarin.Forms.Core/Entry.cs +++ b/Xamarin.Forms.Core/Entry.cs @@ -29,6 +29,8 @@ namespace Xamarin.Forms public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; + public static readonly BindableProperty VerticalTextAlignmentProperty = TextAlignmentElement.VerticalTextAlignmentProperty; + public static readonly BindableProperty FontFamilyProperty = FontElement.FontFamilyProperty; public static readonly BindableProperty FontSizeProperty = FontElement.FontSizeProperty; @@ -54,6 +56,12 @@ namespace Xamarin.Forms set { SetValue(TextAlignmentElement.HorizontalTextAlignmentProperty, value); } } + public TextAlignment VerticalTextAlignment + { + get { return (TextAlignment)GetValue(TextAlignmentElement.VerticalTextAlignmentProperty); } + set { SetValue(TextAlignmentElement.VerticalTextAlignmentProperty, value); } + } + public bool IsPassword { get { return (bool)GetValue(IsPasswordProperty); } diff --git a/Xamarin.Forms.Core/ITextAlignmentElement.cs b/Xamarin.Forms.Core/ITextAlignmentElement.cs index b974080ce..74393c818 100644 --- a/Xamarin.Forms.Core/ITextAlignmentElement.cs +++ b/Xamarin.Forms.Core/ITextAlignmentElement.cs @@ -5,6 +5,8 @@ //note to implementor: implement the properties publicly TextAlignment HorizontalTextAlignment { get; } + TextAlignment VerticalTextAlignment { get; } + //note to implementor: but implement the methods explicitly void OnHorizontalTextAlignmentPropertyChanged(TextAlignment oldValue, TextAlignment newValue); } diff --git a/Xamarin.Forms.Core/Label.cs b/Xamarin.Forms.Core/Label.cs index 50dcded5b..7210624fb 100644 --- a/Xamarin.Forms.Core/Label.cs +++ b/Xamarin.Forms.Core/Label.cs @@ -123,7 +123,7 @@ namespace Xamarin.Forms get { return (TextAlignment)GetValue(TextAlignmentElement.HorizontalTextAlignmentProperty); } set { SetValue(TextAlignmentElement.HorizontalTextAlignmentProperty, value); } } - + public LineBreakMode LineBreakMode { get { return (LineBreakMode)GetValue(LineBreakModeProperty); } @@ -141,12 +141,13 @@ namespace Xamarin.Forms get { return (Color)GetValue(TextElement.TextColorProperty); } set { SetValue(TextElement.TextColorProperty, value); } } - + public double CharacterSpacing { get { return (double)GetValue(TextElement.CharacterSpacingProperty); } set { SetValue(TextElement.CharacterSpacingProperty, value); } } + public TextAlignment VerticalTextAlignment { get { return (TextAlignment)GetValue(VerticalTextAlignmentProperty); } diff --git a/Xamarin.Forms.Core/Properties/AssemblyInfo.cs b/Xamarin.Forms.Core/Properties/AssemblyInfo.cs index f41f968d2..ea0f75483 100644 --- a/Xamarin.Forms.Core/Properties/AssemblyInfo.cs +++ b/Xamarin.Forms.Core/Properties/AssemblyInfo.cs @@ -76,7 +76,7 @@ using Xamarin.Forms.StyleSheets; [assembly: StyleProperty("text-decoration", typeof(IDecorableTextElement), nameof(DecorableTextElement.TextDecorationsProperty))] [assembly: StyleProperty("transform", typeof(VisualElement), nameof(VisualElement.TransformProperty))] [assembly: StyleProperty("transform-origin", typeof(VisualElement), nameof(VisualElement.TransformOriginProperty))] -//[assembly: StyleProperty("vertical-align", /*typeof(Label), nameof(Label.VerticalTextAlignmentProperty)*/)] +[assembly: StyleProperty("vertical-align", typeof(ITextAlignmentElement), nameof(TextAlignmentElement.VerticalTextAlignmentProperty))] [assembly: StyleProperty("visibility", typeof(VisualElement), nameof(VisualElement.IsVisibleProperty), Inherited = true)] [assembly: StyleProperty("width", typeof(VisualElement), nameof(VisualElement.WidthRequestProperty))] [assembly: StyleProperty("line-height", typeof(ILineHeightElement), nameof(LineHeightElement.LineHeightProperty), Inherited = true)] @@ -109,7 +109,7 @@ using Xamarin.Forms.StyleSheets; [assembly: StyleProperty("-xf-spacing", typeof(StackLayout), nameof(StackLayout.SpacingProperty))] [assembly: StyleProperty("-xf-orientation", typeof(StackLayout), nameof(StackLayout.OrientationProperty))] [assembly: StyleProperty("-xf-visual", typeof(VisualElement), nameof(VisualElement.VisualProperty))] -[assembly: StyleProperty("-xf-vertical-text-alignment", typeof(Label), nameof(Label.VerticalTextAlignmentProperty))] +[assembly: StyleProperty("-xf-vertical-text-alignment", typeof(Label), nameof(TextAlignmentElement.VerticalTextAlignmentProperty))] [assembly: StyleProperty("-xf-thumb-color", typeof(Switch), nameof(Switch.ThumbColorProperty))] //shell diff --git a/Xamarin.Forms.Core/SearchBar.cs b/Xamarin.Forms.Core/SearchBar.cs index c182bc3ba..d1e2a3f48 100644 --- a/Xamarin.Forms.Core/SearchBar.cs +++ b/Xamarin.Forms.Core/SearchBar.cs @@ -36,6 +36,8 @@ namespace Xamarin.Forms public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; + public static readonly BindableProperty VerticalTextAlignmentProperty = TextAlignmentElement.VerticalTextAlignmentProperty; + public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty; public static readonly BindableProperty CharacterSpacingProperty = TextElement.CharacterSpacingProperty; @@ -54,6 +56,12 @@ namespace Xamarin.Forms set { SetValue(TextAlignmentElement.HorizontalTextAlignmentProperty, value); } } + public TextAlignment VerticalTextAlignment + { + get { return (TextAlignment)GetValue(TextAlignmentElement.VerticalTextAlignmentProperty); } + set { SetValue(TextAlignmentElement.VerticalTextAlignmentProperty, value); } + } + public string Placeholder { get => (string)GetValue(PlaceholderElement.PlaceholderProperty); set => SetValue(PlaceholderElement.PlaceholderProperty, value); diff --git a/Xamarin.Forms.Core/Shell/SearchHandler.cs b/Xamarin.Forms.Core/Shell/SearchHandler.cs index f9f9a7442..e7d2afd4a 100644 --- a/Xamarin.Forms.Core/Shell/SearchHandler.cs +++ b/Xamarin.Forms.Core/Shell/SearchHandler.cs @@ -96,6 +96,8 @@ namespace Xamarin.Forms public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; + public static readonly BindableProperty VerticalTextAlignmentProperty = TextAlignmentElement.VerticalTextAlignmentProperty; + void ITextAlignmentElement.OnHorizontalTextAlignmentPropertyChanged(TextAlignment oldValue, TextAlignment newValue) { } @@ -106,6 +108,12 @@ namespace Xamarin.Forms set { SetValue(TextAlignmentElement.HorizontalTextAlignmentProperty, value); } } + public TextAlignment VerticalTextAlignment + { + get { return (TextAlignment)GetValue(TextAlignmentElement.VerticalTextAlignmentProperty); } + set { SetValue(TextAlignmentElement.VerticalTextAlignmentProperty, value); } + } + public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty; public static readonly BindableProperty CharacterSpacingProperty = TextElement.CharacterSpacingProperty; diff --git a/Xamarin.Forms.Core/TextAlignmentElement.cs b/Xamarin.Forms.Core/TextAlignmentElement.cs index 4e34a2d49..260eae34f 100644 --- a/Xamarin.Forms.Core/TextAlignmentElement.cs +++ b/Xamarin.Forms.Core/TextAlignmentElement.cs @@ -3,9 +3,12 @@ static class TextAlignmentElement { public static readonly BindableProperty HorizontalTextAlignmentProperty = - BindableProperty.Create(nameof(ITextAlignmentElement.HorizontalTextAlignment), typeof(TextAlignment), typeof(EntryCell), TextAlignment.Start, + BindableProperty.Create(nameof(ITextAlignmentElement.HorizontalTextAlignment), typeof(TextAlignment), typeof(ITextAlignmentElement), TextAlignment.Start, propertyChanged: OnHorizontalTextAlignmentPropertyChanged); + public static readonly BindableProperty VerticalTextAlignmentProperty = + BindableProperty.Create(nameof(ITextAlignmentElement.VerticalTextAlignment), typeof(TextAlignment), typeof(ITextAlignmentElement), TextAlignment.Center); + static void OnHorizontalTextAlignmentPropertyChanged(BindableObject bindable, object oldValue, object newValue) { ((ITextAlignmentElement)bindable).OnHorizontalTextAlignmentPropertyChanged((TextAlignment)oldValue, (TextAlignment)newValue); diff --git a/Xamarin.Forms.CustomAttributes/TestAttributes.cs b/Xamarin.Forms.CustomAttributes/TestAttributes.cs index 42d0030d4..d6b51f91f 100644 --- a/Xamarin.Forms.CustomAttributes/TestAttributes.cs +++ b/Xamarin.Forms.CustomAttributes/TestAttributes.cs @@ -526,6 +526,12 @@ namespace Xamarin.Forms.CustomAttributes HorizontalTextAlignmentPlaceholderStart, HorizontalTextAlignmentPlaceholderCenter, HorizontalTextAlignmentPlaceholderEnd, + VerticalTextAlignmentStart, + VerticalTextAlignmentCenter, + VerticalTextAlignmentEnd, + VerticalTextAlignmentPlaceholderStart, + VerticalTextAlignmentPlaceholderCenter, + VerticalTextAlignmentPlaceholderEnd, FontAttributes, FontFamily, FontSize, @@ -680,9 +686,15 @@ namespace Xamarin.Forms.CustomAttributes TextAlignmentStart, TextAlignmentCenter, TextAlignmentEnd, + TextVerticalAlignmentStart, + TextVerticalAlignmentCenter, + TextVerticalAlignmentEnd, PlaceholderAlignmentStart, PlaceholderAlignmentCenter, PlaceholderAlignmentEnd, + PlaceholderVerticalAlignmentStart, + PlaceholderVerticalAlignmentCenter, + PlaceholderVerticalAlignmentEnd, TextColor, PlaceholderColor } diff --git a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs index 8cd40357f..a53213d6f 100644 --- a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs @@ -26,6 +26,7 @@ namespace Xamarin.Forms.Platform.Android UpdatePlaceholder(); UpdateKeyboard(); UpdateHorizontalTextAlignment(); + UpdateVerticalTextAlignment(); UpdateText(); UpdateIsEnabled(); UpdateHeight(); @@ -53,6 +54,8 @@ namespace Xamarin.Forms.Platform.Android UpdateLabelColor(); else if (e.PropertyName == EntryCell.HorizontalTextAlignmentProperty.PropertyName) UpdateHorizontalTextAlignment(); + else if (e.PropertyName == EntryCell.VerticalTextAlignmentProperty.PropertyName) + UpdateVerticalTextAlignment(); else if (e.PropertyName == Cell.IsEnabledProperty.PropertyName) UpdateIsEnabled(); else if (e.PropertyName == "RenderHeight") @@ -95,6 +98,12 @@ namespace Xamarin.Forms.Platform.Android _view.EditText.UpdateHorizontalAlignment(entryCell.HorizontalTextAlignment, _view.Context.HasRtlSupport()); } + void UpdateVerticalTextAlignment() + { + var entryCell = (EntryCell)Cell; + _view.EditText.UpdateVerticalAlignment(entryCell.VerticalTextAlignment); + } + void UpdateIsEnabled() { var entryCell = (EntryCell)Cell; diff --git a/Xamarin.Forms.Platform.Android/Extensions/FlowDirectionExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/FlowDirectionExtensions.cs index f5159824b..0747cdd1f 100644 --- a/Xamarin.Forms.Platform.Android/Extensions/FlowDirectionExtensions.cs +++ b/Xamarin.Forms.Platform.Android/Extensions/FlowDirectionExtensions.cs @@ -1,9 +1,6 @@ using Android.OS; -using Android.Widget; -using Xamarin.Forms.Internals; using ALayoutDirection = Android.Views.LayoutDirection; using AView = Android.Views.View; -using AGravityFlags = Android.Views.GravityFlags; namespace Xamarin.Forms.Platform.Android @@ -34,13 +31,5 @@ namespace Xamarin.Forms.Platform.Android else if (controller.EffectiveFlowDirection.IsLeftToRight()) view.LayoutDirection = ALayoutDirection.Ltr; } - - internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, bool hasRtlSupport, AGravityFlags orMask = AGravityFlags.NoGravity) - { - if ((int)Build.VERSION.SdkInt < 17 || !hasRtlSupport) - view.Gravity = alignment.ToHorizontalGravityFlags() | orMask; - else - view.TextAlignment = alignment.ToTextAlignment(); - } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Extensions/TextAlignmentExtensions.cs b/Xamarin.Forms.Platform.Android/Extensions/TextAlignmentExtensions.cs new file mode 100644 index 000000000..727a632b7 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/Extensions/TextAlignmentExtensions.cs @@ -0,0 +1,22 @@ +using Android.OS; +using Android.Widget; +using AGravityFlags = Android.Views.GravityFlags; + +namespace Xamarin.Forms.Platform.Android +{ + internal static class TextAlignmentExtensions + { + internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, bool hasRtlSupport, AGravityFlags orMask = AGravityFlags.NoGravity) + { + if ((int)Build.VERSION.SdkInt < 17 || !hasRtlSupport) + view.Gravity = alignment.ToHorizontalGravityFlags() | orMask; + else + view.TextAlignment = alignment.ToTextAlignment(); + } + + internal static void UpdateVerticalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity) + { + view.Gravity = alignment.ToVerticalGravityFlags() | orMask; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs index 36c54bb28..50e049121 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs @@ -179,7 +179,8 @@ namespace Xamarin.Forms.Platform.Android UpdateInputType(); UpdateColor(); UpdateCharacterSpacing(); - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + UpdateVerticalTextAlignment(); UpdateFont(); UpdatePlaceholderColor(); UpdateMaxLength(); @@ -242,7 +243,9 @@ namespace Xamarin.Forms.Platform.Android else if (e.PropertyName == Entry.IsTextPredictionEnabledProperty.PropertyName) UpdateInputType(); else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + else if(e.PropertyName == Entry.VerticalTextAlignmentProperty.PropertyName) + UpdateVerticalTextAlignment(); else if (e.PropertyName == Entry.CharacterSpacingProperty.PropertyName) UpdateCharacterSpacing(); else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName) @@ -254,7 +257,7 @@ namespace Xamarin.Forms.Platform.Android else if (e.PropertyName == Entry.PlaceholderColorProperty.PropertyName) UpdatePlaceholderColor(); else if (e.PropertyName == VisualElement.FlowDirectionProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); else if (e.PropertyName == InputView.MaxLengthProperty.PropertyName) UpdateMaxLength(); else if (e.PropertyName == PlatformConfiguration.AndroidSpecific.Entry.ImeOptionsProperty.PropertyName) @@ -288,11 +291,16 @@ namespace Xamarin.Forms.Platform.Android EditText.ImeOptions = _currentInputImeFlag; } - void UpdateAlignment() + void UpdateHorizontalTextAlignment() { EditText.UpdateHorizontalAlignment(Element.HorizontalTextAlignment, Context.HasRtlSupport()); } + void UpdateVerticalTextAlignment() + { + EditText.UpdateVerticalAlignment(Element.VerticalTextAlignment); + } + protected abstract void UpdateColor(); protected abstract void UpdateTextColor(Color color); diff --git a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs index 88a1a9e06..414a595cd 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SearchBarRenderer.cs @@ -111,7 +111,8 @@ namespace Xamarin.Forms.Platform.Android UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + UpdateVerticalTextAlignment(); UpdateTextColor(); UpdateCharacterSpacing(); UpdatePlaceholderColor(); @@ -145,13 +146,15 @@ namespace Xamarin.Forms.Platform.Android else if (e.PropertyName == SearchBar.FontSizeProperty.PropertyName) UpdateFont(); else if (e.PropertyName == SearchBar.HorizontalTextAlignmentProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + else if (e.PropertyName == SearchBar.VerticalOptionsProperty.PropertyName) + UpdateVerticalTextAlignment(); else if (e.PropertyName == SearchBar.TextColorProperty.PropertyName) UpdateTextColor(); else if (e.PropertyName == SearchBar.PlaceholderColorProperty.PropertyName) UpdatePlaceholderColor(); else if (e.PropertyName == VisualElement.FlowDirectionProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); else if (e.PropertyName == InputView.MaxLengthProperty.PropertyName) UpdateMaxLength(); else if(e.PropertyName == InputView.KeyboardProperty.PropertyName) @@ -166,7 +169,7 @@ namespace Xamarin.Forms.Platform.Android ClearFocus(Control); } - void UpdateAlignment() + void UpdateHorizontalTextAlignment() { _editText = _editText ?? Control.GetChildrenOfType().FirstOrDefault(); @@ -176,6 +179,16 @@ namespace Xamarin.Forms.Platform.Android _editText.UpdateHorizontalAlignment(Element.HorizontalTextAlignment, Context.HasRtlSupport(), Xamarin.Forms.TextAlignment.Center.ToVerticalGravityFlags()); } + void UpdateVerticalTextAlignment() + { + _editText = _editText ?? Control.GetChildrenOfType().FirstOrDefault(); + + if (_editText == null) + return; + + _editText.UpdateVerticalAlignment(Element.VerticalTextAlignment, Xamarin.Forms.TextAlignment.Center.ToVerticalGravityFlags()); + } + void UpdateCancelButtonColor() { int searchViewCloseButtonId = Control.Resources.GetIdentifier("android:id/search_close_btn", null, null); @@ -329,4 +342,4 @@ namespace Xamarin.Forms.Platform.Android return LocalizedDigitsKeyListener.Create(inputTypes); } } -} \ No newline at end of file +} diff --git a/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs b/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs index fa1637317..c3f238118 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/SearchHandlerAppearanceTracker.cs @@ -39,7 +39,8 @@ namespace Xamarin.Forms.Platform.Android _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, false); UpdateSearchBarColors(); UpdateFont(); - UpdateTextAlignment(); + UpdateHorizontalTextAlignment(); + UpdateVerticalTextAlignment(); UpdateInputType(); } @@ -87,7 +88,11 @@ namespace Xamarin.Forms.Platform.Android } else if (e.Is(SearchHandler.HorizontalTextAlignmentProperty)) { - UpdateTextAlignment(); + UpdateHorizontalTextAlignment(); + } + else if (e.Is(SearchHandler.VerticalTextAlignmentProperty)) + { + UpdateVerticalTextAlignment(); } } @@ -110,11 +115,16 @@ namespace Xamarin.Forms.Platform.Android _hintColorSwitcher?.UpdateTextColor(_editText, _searchHandler.PlaceholderColor, _editText.SetHintTextColor); } - void UpdateTextAlignment() + void UpdateHorizontalTextAlignment() { _editText.UpdateHorizontalAlignment(_searchHandler.HorizontalTextAlignment, _control.Context.HasRtlSupport(), Xamarin.Forms.TextAlignment.Center.ToVerticalGravityFlags()); } + void UpdateVerticalTextAlignment() + { + _editText.UpdateVerticalAlignment(_searchHandler.VerticalTextAlignment, Xamarin.Forms.TextAlignment.Center.ToVerticalGravityFlags()); + } + void UpdateBackgroundColor() { var linearLayout = (_control as ViewGroup).GetChildrenOfType().FirstOrDefault(); diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj index 990eeb95c..d0a1198e9 100644 --- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj +++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj @@ -102,6 +102,7 @@ + diff --git a/Xamarin.Forms.Platform.UAP/EntryRenderer.cs b/Xamarin.Forms.Platform.UAP/EntryRenderer.cs index bc773535a..02f1c7b74 100644 --- a/Xamarin.Forms.Platform.UAP/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/EntryRenderer.cs @@ -58,7 +58,8 @@ namespace Xamarin.Forms.Platform.UWP UpdateTextColor(); UpdateFont(); UpdateCharacterSpacing(); - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + UpdateVerticalTextAlignment(); UpdatePlaceholderColor(); UpdateMaxLength(); UpdateDetectReadingOrderFromContent(); @@ -128,11 +129,13 @@ namespace Xamarin.Forms.Platform.UWP else if (e.PropertyName == Entry.FontSizeProperty.PropertyName) UpdateFont(); else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); + else if (e.PropertyName == Entry.VerticalTextAlignmentProperty.PropertyName) + UpdateVerticalTextAlignment(); else if (e.PropertyName == Entry.PlaceholderColorProperty.PropertyName) UpdatePlaceholderColor(); else if (e.PropertyName == VisualElement.FlowDirectionProperty.PropertyName) - UpdateAlignment(); + UpdateHorizontalTextAlignment(); else if (e.PropertyName == InputView.MaxLengthProperty.PropertyName) UpdateMaxLength(); else if (e.PropertyName == Specifics.DetectReadingOrderFromContentProperty.PropertyName) @@ -184,11 +187,16 @@ namespace Xamarin.Forms.Platform.UWP ((IEntryController)Element).SendCompleted(); } - void UpdateAlignment() + void UpdateHorizontalTextAlignment() { Control.TextAlignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(((IVisualElementController)Element).EffectiveFlowDirection); } + void UpdateVerticalTextAlignment() + { + Control.VerticalContentAlignment = Element.VerticalTextAlignment.ToNativeVerticalAlignment(); + } + void UpdateFont() { if (Control == null) diff --git a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml index bdf5cc0c1..fb0809d91 100644 --- a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml +++ b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml @@ -220,7 +220,8 @@ IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.Row="1" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" - VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled" /> + VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="Disabled" + VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> + Converter={StaticResource AlignmentConverter}}" + VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>