Skip to content

Commit eb79439

Browse files
Fix SfTextInputLayout crash on very small container widths
Co-authored-by: PaulAndersonS <[email protected]>
1 parent f11e3e3 commit eb79439

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

maui/src/TextInputLayout/SfTextInputLayout.Methods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ void UpdateContentPosition()
10611061
_viewBounds.Width -= (float)(IconSize * (IsUpDownVerticalAlignment ? 1 : 2));
10621062
}
10631063

1064-
if (_viewBounds.Height >= 0 || _viewBounds.Width >= 0)
1064+
if (_viewBounds.Height >= 0 && _viewBounds.Width >= 0)
10651065
{
10661066
AbsoluteLayout.SetLayoutBounds(Content, _viewBounds);
10671067
}
@@ -1117,7 +1117,7 @@ void UpdateLeadingViewPosition()
11171117
LeadingView.VerticalOptions = LayoutOptions.End;
11181118
}
11191119

1120-
if (_viewBounds.Height >= 0 || _viewBounds.Width >= 0)
1120+
if (_viewBounds.Height >= 0 && _viewBounds.Width >= 0)
11211121
{
11221122
AbsoluteLayout.SetLayoutBounds(LeadingView, _viewBounds);
11231123
}
@@ -1151,7 +1151,7 @@ void UpdateTrailingViewPosition()
11511151
TrailingView.VerticalOptions = LayoutOptions.End;
11521152
}
11531153

1154-
if (_viewBounds.Height >= 0 || _viewBounds.Width >= 0)
1154+
if (_viewBounds.Height >= 0 && _viewBounds.Width >= 0)
11551155
{
11561156
AbsoluteLayout.SetLayoutBounds(TrailingView, _viewBounds);
11571157
}

maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Layout/SfTextInputLayoutUnitTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,51 @@ public void Content_TimePicker(ContainerType container)
11911191
Assert.Equal(new TimeSpan(10, 30, 0), timePicker.Time);
11921192
}
11931193

1194+
[Fact]
1195+
public void VerySmallContainerWidth_ShouldNotCrash()
1196+
{
1197+
// Test for the fix of issue where very small container widths cause Android crash
1198+
// with Java.Lang.IllegalArgumentException: 'Layout: -46 < 0'
1199+
var inputLayout = new SfTextInputLayout
1200+
{
1201+
Content = new Entry { Text = "Test" },
1202+
Hint = "Name",
1203+
WidthRequest = 10, // Very small width that could cause negative layout bounds
1204+
HeightRequest = 50
1205+
};
1206+
1207+
// The control should handle very small dimensions gracefully without throwing exceptions
1208+
Assert.NotNull(inputLayout);
1209+
Assert.NotNull(inputLayout.Content);
1210+
Assert.Equal("Test", ((Entry)inputLayout.Content).Text);
1211+
Assert.Equal("Name", inputLayout.Hint);
1212+
}
1213+
1214+
[Fact]
1215+
public void VerySmallContainerWidthWithLeadingAndTrailingViews_ShouldNotCrash()
1216+
{
1217+
// Test for the fix where very small container widths with leading/trailing views cause crashes
1218+
var inputLayout = new SfTextInputLayout
1219+
{
1220+
Content = new Entry { Text = "Test" },
1221+
Hint = "Name",
1222+
LeadingView = new Label { Text = "L" },
1223+
TrailingView = new Label { Text = "T" },
1224+
ShowLeadingView = true,
1225+
ShowTrailingView = true,
1226+
WidthRequest = 10, // Very small width that could cause negative layout bounds
1227+
HeightRequest = 50
1228+
};
1229+
1230+
// The control should handle very small dimensions gracefully without throwing exceptions
1231+
Assert.NotNull(inputLayout);
1232+
Assert.NotNull(inputLayout.Content);
1233+
Assert.NotNull(inputLayout.LeadingView);
1234+
Assert.NotNull(inputLayout.TrailingView);
1235+
Assert.True(inputLayout.ShowLeadingView);
1236+
Assert.True(inputLayout.ShowTrailingView);
1237+
}
1238+
11941239

11951240
#endregion
11961241
}

0 commit comments

Comments
 (0)