Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 67a216d

Browse files
authored
[Android] Fix issue updating the Label size changing the MaxLines (#11896) fixes #11875
* Added repro sample * Fix the issue
1 parent 0fdeee5 commit 67a216d

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage
3+
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
x:Class="Xamarin.Forms.Controls.Issues.Issue11875"
10+
Title="Issue 11875">
11+
<StackLayout>
12+
<Label
13+
Padding="12"
14+
BackgroundColor="Black"
15+
TextColor="White"
16+
Text="If by increasing or decreasing the number of MaxLines, the Label size is adjusted correctly, the test has passed."/>
17+
<Label
18+
MaxLines="{Binding MaxLines}"
19+
Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." />
20+
<Label
21+
FontSize="Micro"
22+
Text="{Binding MaxLines}"/>
23+
<Button
24+
Command="{Binding IncreaseCommand}"
25+
Text="Increase MaxLines"/>
26+
<Button
27+
Command="{Binding DecreaseCommand}"
28+
Text="Decrease MaxLines"/>
29+
</StackLayout>
30+
</controls:TestContentPage>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
using Xamarin.Forms.Xaml;
4+
using System.Windows.Input;
5+
6+
#if UITEST
7+
using Xamarin.UITest;
8+
using Xamarin.UITest.Queries;
9+
using NUnit.Framework;
10+
using Xamarin.Forms.Core.UITests;
11+
#endif
12+
13+
namespace Xamarin.Forms.Controls.Issues
14+
{
15+
#if UITEST
16+
[Category(UITestCategories.Label)]
17+
#endif
18+
#if APP
19+
[XamlCompilation(XamlCompilationOptions.Compile)]
20+
#endif
21+
[Preserve(AllMembers = true)]
22+
[Issue(IssueTracker.Github, 11875, "[Bug] Label MaxLine not updating value after changing from View Model",
23+
PlatformAffected.Android)]
24+
public partial class Issue11875 : TestContentPage
25+
{
26+
public Issue11875()
27+
{
28+
#if APP
29+
InitializeComponent();
30+
BindingContext = new Issue11875ViewModel();
31+
#endif
32+
}
33+
34+
protected override void Init()
35+
{
36+
37+
}
38+
}
39+
40+
public class Issue11875ViewModel : BindableObject
41+
{
42+
int _maxLines;
43+
44+
public Issue11875ViewModel()
45+
{
46+
MaxLines = 2;
47+
}
48+
49+
public int MaxLines
50+
{
51+
get { return _maxLines; }
52+
set
53+
{
54+
_maxLines = value;
55+
OnPropertyChanged();
56+
}
57+
}
58+
59+
public ICommand IncreaseCommand => new Command(Increase);
60+
public ICommand DecreaseCommand => new Command(Decrease);
61+
62+
void Increase()
63+
{
64+
MaxLines++;
65+
}
66+
67+
void Decrease()
68+
{
69+
if (MaxLines > 0)
70+
MaxLines--;
71+
}
72+
}
73+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@
14841484
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
14851485
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
14861486
<Compile Include="$(MSBuildThisFileDirectory)Issue10608.cs" />
1487+
<Compile Include="$(MSBuildThisFileDirectory)Issue11875.xaml.cs" />
14871488
<Compile Include="$(MSBuildThisFileDirectory)Issue11737.xaml.cs" />
14881489
<Compile Include="$(MSBuildThisFileDirectory)Issue11764.xaml.cs" />
14891490
<Compile Include="$(MSBuildThisFileDirectory)Issue11573.xaml.cs" />
@@ -1777,6 +1778,9 @@
17771778
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11547.xaml">
17781779
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
17791780
</EmbeddedResource>
1781+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11875.xaml">
1782+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
1783+
</EmbeddedResource>
17801784
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11737.xaml">
17811785
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
17821786
</EmbeddedResource>

Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ void UpdateLineBreakMode()
383383
void UpdateMaxLines()
384384
{
385385
this.SetMaxLines(Element);
386+
_lastSizeRequest = null;
386387
}
387388

388389
void UpdateText()

0 commit comments

Comments
 (0)