[Android] Set SingleLine to true when we only have 1 line on a TextView (#932)

* [Android] Set SingleLine to true when we only have 1 line on a TextView

* Fix stray \ char
This commit is contained in:
Rui Marinho 2017-05-26 12:30:01 +01:00 коммит произвёл GitHub
Родитель a9a6a40c67
Коммит 657c3e39f8
6 изменённых файлов: 116 добавлений и 57 удалений

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

@ -0,0 +1,66 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
// Apply the default category of "Issues" to all of the tests in this assembly
// We use this as a catch-all for tests which haven't been individually categorized
#if UITEST
[assembly: NUnit.Framework.Category("Issues")]
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 49069, "Java.Lang.ArrayIndexOutOfBoundsException when rendering long Label on Android", PlatformAffected.Default)]
public class Bugzilla49069 : TestContentPage // or TestMasterDetailPage, etc ...
{
protected override void Init()
{
Label longLabelWithHorizontalTextAlignmentOfEndAndHeadTruncation = new Label
{
AutomationId = "lblLong",
TextColor = Color.Black,
BackgroundColor = Color.Pink,
Text = "This is a long string that should hopefully truncate. It has HeadTruncation enabled and HorizontalTextAlignment = End",
LineBreakMode = LineBreakMode.HeadTruncation,
HorizontalTextAlignment = TextAlignment.End
};
StackLayout vslOuterPage = new StackLayout
{
BackgroundColor = Color.White, // viewModel.PageBackgroundColor,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(0, 0, 0, 0), // gets rid of the white
Padding = new Thickness(0, 10, 0, 10),
Spacing = 0,
Children =
{
longLabelWithHorizontalTextAlignmentOfEndAndHeadTruncation,
}
};
ScrollView sv = new ScrollView
{
Content = vslOuterPage,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Fill,
Orientation = ScrollOrientation.Vertical
};
Content = sv;
}
#if UITEST
[Test]
public void Bugzilla49069Test ()
{
RunningApp.WaitForElement (q => q.Marked ("lblLong"));
}
#endif
}
}

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

@ -550,6 +550,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla54977.xaml.cs">
<DependentUpon>Bugzilla54977.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla49069.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42956.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla38731.cs" />
</ItemGroup>
@ -704,4 +705,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>

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

@ -0,0 +1,45 @@
using Android.Text;
using Android.Widget;
namespace Xamarin.Forms.Platform.Android
{
internal static class TextViewExtensions
{
public static void SetLineBreakMode(this TextView textView, LineBreakMode lineBreakMode)
{
switch (lineBreakMode)
{
case LineBreakMode.NoWrap:
textView.SetMaxLines(1);
textView.SetSingleLine(true);
textView.Ellipsize = null;
break;
case LineBreakMode.WordWrap:
textView.Ellipsize = null;
textView.SetMaxLines(100);
textView.SetSingleLine(false);
break;
case LineBreakMode.CharacterWrap:
textView.Ellipsize = null;
textView.SetMaxLines(100);
textView.SetSingleLine(false);
break;
case LineBreakMode.HeadTruncation:
textView.SetMaxLines(1);
textView.SetSingleLine(true);
textView.Ellipsize = TextUtils.TruncateAt.Start;
break;
case LineBreakMode.TailTruncation:
textView.SetMaxLines(1);
textView.SetSingleLine(true);
textView.Ellipsize = TextUtils.TruncateAt.End;
break;
case LineBreakMode.MiddleTruncation:
textView.SetMaxLines(1);
textView.SetSingleLine(true);
textView.Ellipsize = TextUtils.TruncateAt.Middle;
break;
}
}
}
}

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

@ -255,34 +255,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
void UpdateLineBreakMode()
{
SetSingleLine(false);
switch (Element.LineBreakMode)
{
case LineBreakMode.NoWrap:
SetMaxLines(1);
Ellipsize = null;
break;
case LineBreakMode.WordWrap:
Ellipsize = null;
SetMaxLines(100);
break;
case LineBreakMode.CharacterWrap:
Ellipsize = null;
SetMaxLines(100);
break;
case LineBreakMode.HeadTruncation:
SetMaxLines(1);
Ellipsize = TextUtils.TruncateAt.Start;
break;
case LineBreakMode.TailTruncation:
SetMaxLines(1);
Ellipsize = TextUtils.TruncateAt.End;
break;
case LineBreakMode.MiddleTruncation:
SetMaxLines(1);
Ellipsize = TextUtils.TruncateAt.Middle;
break;
}
this.SetLineBreakMode(Element.LineBreakMode);
_lastSizeRequest = null;
}

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

@ -164,34 +164,7 @@ namespace Xamarin.Forms.Platform.Android
void UpdateLineBreakMode()
{
_view.SetSingleLine(false);
switch (Element.LineBreakMode)
{
case LineBreakMode.NoWrap:
_view.SetMaxLines(1);
_view.Ellipsize = null;
break;
case LineBreakMode.WordWrap:
_view.Ellipsize = null;
_view.SetMaxLines(100);
break;
case LineBreakMode.CharacterWrap:
_view.Ellipsize = null;
_view.SetMaxLines(100);
break;
case LineBreakMode.HeadTruncation:
_view.SetMaxLines(1);
_view.Ellipsize = TextUtils.TruncateAt.Start;
break;
case LineBreakMode.TailTruncation:
_view.SetMaxLines(1);
_view.Ellipsize = TextUtils.TruncateAt.End;
break;
case LineBreakMode.MiddleTruncation:
_view.SetMaxLines(1);
_view.Ellipsize = TextUtils.TruncateAt.Middle;
break;
}
_view.SetLineBreakMode(Element.LineBreakMode);
_lastSizeRequest = null;
}

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

@ -258,6 +258,7 @@
<Compile Include="Renderers\GroupedListViewAdapter.cs" />
<Compile Include="FastRenderers\ImageRenderer.cs" />
<Compile Include="Extensions\ImageViewExtensions.cs" />
<Compile Include="Extensions\TextViewExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.