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

[iOS/macOS] Fix NRE in ButtonRenderer #13137

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue13136"
Title="Issue 13136">
<Grid RowDefinitions="Auto,*">
<Label
Grid.Row="0"
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="Scroll quickly the list. Without crash, the test has passed."/>
<ListView
Grid.Row="1"
SeparatorVisibility="None"
HasUnevenRows="True">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
<x:String>Item 3</x:String>
<x:String>Item 4</x:String>
<x:String>Item 5</x:String>
<x:String>Item 6</x:String>
<x:String>Item 7</x:String>
<x:String>Item 8</x:String>
<x:String>Item 9</x:String>
<x:String>Item 10</x:String>
<x:String>Item 11</x:String>
<x:String>Item 12</x:String>
<x:String>Item 13</x:String>
<x:String>Item 14</x:String>
<x:String>Item 15</x:String>
<x:String>Item 16</x:String>
<x:String>Item 17</x:String>
<x:String>Item 18</x:String>
<x:String>Item 19</x:String>
<x:String>Item 20</x:String>
<x:String>Item 21</x:String>
<x:String>Item 22</x:String>
<x:String>Item 23</x:String>
<x:String>Item 24</x:String>
<x:String>Item 25</x:String>
<x:String>Item 26</x:String>
<x:String>Item 27</x:String>
<x:String>Item 28</x:String>
<x:String>Item 29</x:String>
<x:String>Item 30</x:String>
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label
Text="Issue 13136"/>
<Button
Grid.Row="1"
BackgroundColor="Gray"
TextColor="White"
Text="{Binding}"
Margin="0, 12"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.CollectionView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13136, "[Bug] Crash in ButtonRenderer on iOS",
PlatformAffected.iOS)]
public partial class Issue13136 : TestContentPage
{
public Issue13136()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue12512.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12685.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12642.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13136.xaml.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -2026,6 +2027,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12084.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13136.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.MacOS/Renderers/BoxViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void Layout()
{
base.Layout();

if (_previousSize != Bounds.Size)
if (Element != null && _previousSize != Bounds.Size)
SetBackground(Element.Background);

_previousSize = Bounds.Size;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.MacOS/Renderers/EditorRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void Layout()
{
base.Layout();

if (_previousSize != Bounds.Size)
if (Element != null && _previousSize != Bounds.Size)
SetBackground(Element.Background);

_previousSize = Bounds.Size;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void Layout()
{
base.Layout();

if (_previousSize != Bounds.Size)
if (Element != null && _previousSize != Bounds.Size)
SetBackground(Element.Background);

_previousSize = Bounds.Size;
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/BoxRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Draw(RectangleF rect)

public override void LayoutSubviews()
{
if (_previousSize != Bounds.Size)
if (Element != null && _previousSize != Bounds.Size)
{
SetBackground(Element.Background);
SetNeedsDisplay();
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override void Draw(CGRect rect)

public override void LayoutSubviews()
{
if (_previousSize != Bounds.Size)
if (Element != null && _previousSize != Bounds.Size)
{
SetBackground(Element.Background);
SetNeedsDisplay();
Expand Down