diff options
author | Samantha Houts <samantha@teamredwall.com> | 2017-01-12 11:48:30 -0800 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-01-12 11:48:30 -0800 |
commit | 3af99cbbe145a876cc9839af0adead83695b5445 (patch) | |
tree | a94639d66151591abac7ecc356cf947e12c8f4a2 | |
parent | e7a7a57e4b2f7db71137e702be2663cf4f37d1b4 (diff) | |
download | xamarin-forms-3af99cbbe145a876cc9839af0adead83695b5445.tar.gz xamarin-forms-3af99cbbe145a876cc9839af0adead83695b5445.tar.bz2 xamarin-forms-3af99cbbe145a876cc9839af0adead83695b5445.zip |
[iOS] Labels with WordWrap or CharacterWrap will Expand (#529)
* Add reproduction for 28650
* [iOS] Expand the label to fill width if wrapping
Also, simplify the `if` statement, since `LineBreakMode` is not a flags
enum and the only excluded member was `None`.
* Test two small labels next to each other in horizontal layout
7 files changed, 172 insertions, 2 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/Resources/drawable/caret_r.png b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/caret_r.png Binary files differnew file mode 100644 index 00000000..bcf0ffb9 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.Android/Resources/drawable/caret_r.png diff --git a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj index 9a907004..642f866b 100644 --- a/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj +++ b/Xamarin.Forms.ControlGallery.Android/Xamarin.Forms.ControlGallery.Android.csproj @@ -262,6 +262,9 @@ <ItemGroup> <TransformFile Include="Properties\AndroidManifest.xml" /> </ItemGroup> + <ItemGroup> + <BundleResource Include="Resources\drawable\caret_r.png" /> + </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets')" /> diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj index 848addd5..3eeb9484 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj +++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj @@ -201,6 +201,7 @@ <Content Include="bank.png" /> <Content Include="calculator%402x.png" /> <Content Include="calculator.png" /> + <BundleResource Include="caret_r.png" /> <Content Include="cover1.jpg" /> <Content Include="crimson.jpg" /> <Content Include="Default-568h%402x.png" /> diff --git a/Xamarin.Forms.ControlGallery.iOS/caret_r.png b/Xamarin.Forms.ControlGallery.iOS/caret_r.png Binary files differnew file mode 100644 index 00000000..bcf0ffb9 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.iOS/caret_r.png diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28650.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28650.cs new file mode 100644 index 00000000..6415d902 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla28650.cs @@ -0,0 +1,165 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Collections.Generic; +using System; +using System.Threading.Tasks; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 928650, "In a Listview on iOS, \"andExpand\" does not expand when text is two lines long")] + public class Bugzilla28650 : TestContentPage + { + const string caret_image = "caret_r.png"; + + [Preserve(AllMembers = true)] + internal class MyTextCell : ViewCell + { + StackLayout _viewLayout; + Label _descriptionLabel; + Image _caret; + + public MyTextCell() + { + _descriptionLabel = new Label + { + HorizontalOptions = LayoutOptions.FillAndExpand, + FontSize = 14, + }; + _descriptionLabel.SetBinding(Label.TextProperty, "."); + + _caret = new Image + { + HorizontalOptions = LayoutOptions.End, + Source = ImageSource.FromFile(caret_image), + HeightRequest = 20, + Aspect = Aspect.AspectFit, + BackgroundColor = Color.Green + }; + + _viewLayout = new StackLayout + { + Orientation = StackOrientation.Horizontal, + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { _descriptionLabel, _caret }, + }; + + View = _viewLayout; + } + } + + protected override void Init() + { + var items = new List<string> + { + "Short Desc", + "Thisis averylong description withwords thatarelong", + "Item Three", + "Item Four", + "Short Desc again", + }; + + var cell = new DataTemplate(typeof(MyTextCell)); + var menuView = new ListView + { + ItemTemplate = cell, + ItemsSource = items, + HasUnevenRows = true + }; + + // let's try the same configuration outside of a ListView + var grid = new Grid(); + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 300 }); + + const int column = 0; + int currentRow = 0; + grid.AddChild(new Label { Text = "If the carets do not ALL align, this test has failed." }, column, currentRow++, columnspan: 2); + grid.AddChild(menuView, column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.NoWrap), column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.CharacterWrap), column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.HeadTruncation), column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.MiddleTruncation), column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.TailTruncation), column, currentRow++); + grid.AddChild(GetStackLayout("Thisis averylong description withwords thatarelong", LineBreakMode.WordWrap), column, currentRow++); + grid.AddChild(GetStackLayout("Short desc", LineBreakMode.WordWrap), column, currentRow++); + + + grid.AddChild(new StackLayout + { + Orientation = StackOrientation.Horizontal, + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.FillAndExpand, + FontSize = 14, + Text = "1", + LineBreakMode = LineBreakMode.WordWrap, + BackgroundColor = Color.Red + }, new Label + { + HorizontalOptions = LayoutOptions.FillAndExpand, + FontSize = 14, + Text = "2", + LineBreakMode = LineBreakMode.WordWrap, + BackgroundColor = Color.Blue + } + }, + }, column, currentRow++); + + grid.AddChild(new StackLayout + { + Orientation = StackOrientation.Horizontal, + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.FillAndExpand, + FontSize = 14, + Text = "1", + LineBreakMode = LineBreakMode.WordWrap, + BackgroundColor = Color.Red + }, new Label + { + HorizontalOptions = LayoutOptions.Start, + FontSize = 14, + Text = "2", + LineBreakMode = LineBreakMode.WordWrap, + BackgroundColor = Color.Blue + } + }, + }, column, currentRow++); + + Content = grid; + } + private static StackLayout GetStackLayout(string Text, LineBreakMode breakMode) + { + return new StackLayout + { + Orientation = StackOrientation.Horizontal, + HorizontalOptions = LayoutOptions.FillAndExpand, + Children = { + new Label + { + HorizontalOptions = LayoutOptions.FillAndExpand, + FontSize = 14, + Text = Text, + LineBreakMode = breakMode + }, new Image + { + HorizontalOptions = LayoutOptions.End, + Source = ImageSource.FromFile(caret_image), + HeightRequest = 20, + Aspect = Aspect.AspectFit, + BackgroundColor = Color.Green + } + }, + }; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 16a2199d..e040a049 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -219,6 +219,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40722.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41153.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44129.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla28650.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla37431.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44777.cs" /> <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" /> diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs index 0a9ef79a..58312f8a 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs @@ -26,9 +26,9 @@ namespace Xamarin.Forms.Platform.iOS var result = base.GetDesiredSize(widthConstraint, heightConstraint); result.Minimum = new Size(Math.Min(10, result.Request.Width), result.Request.Height); - if ((Element.LineBreakMode & (LineBreakMode.TailTruncation | LineBreakMode.HeadTruncation | LineBreakMode.MiddleTruncation)) != 0) + if (Element.LineBreakMode != LineBreakMode.NoWrap) { - if (result.Request.Width > widthConstraint) + if (result.Request.Width > widthConstraint || Element.LineBreakMode == LineBreakMode.WordWrap || Element.LineBreakMode == LineBreakMode.CharacterWrap) result.Request = new Size(Math.Max(result.Minimum.Width, widthConstraint), result.Request.Height); } |