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

[macOS] Hang App scaling a View to zero #13005

Merged
merged 11 commits into from
May 21, 2021
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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.Issue8981"
Title="Issue 8981">
<Grid RowDefinitions="Auto,*">
<Label
Grid.Row="0"
AutomationId = "TestReady"
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="Without hang, the test has passed."/>
<StackLayout
Grid.Row="1">
<Label
x:Name="TestLabel"
Text="#8981"
HorizontalOptions="Center"
VerticalOptions="Center" />
<Label
Text="Scale X:" />
<Slider
Minimum="-11"
Maximum="11"
Value="1"
ValueChanged="OnScaleXChanged" />
<Label
Text="Scale Y:" />
<Slider
Minimum="-11"
Maximum="11"
Value="1"
ValueChanged="OnScaleYChanged" />
<Label
Text="Scale:" />
<Slider
Minimum="-11"
Maximum="11"
Value="1"
ValueChanged="OnScaleChanged" />
</StackLayout>
</Grid>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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, 8981, "[Bug] [macOS] Hang App scaling a View to zero",
PlatformAffected.macOS)]
public partial class Issue8981 : TestContentPage
{
public Issue8981()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{

}
#if APP
protected override async void OnAppearing()
{
base.OnAppearing();

await TestLabel.ScaleTo(0, 1000);
await TestLabel.ScaleTo(1, 1000);
}

void OnScaleXChanged(object sender, ValueChangedEventArgs e)
{
TestLabel.ScaleX = e.NewValue;
}

void OnScaleYChanged(object sender, ValueChangedEventArgs e)
{
TestLabel.ScaleY = e.NewValue;
}

void OnScaleChanged(object sender, ValueChangedEventArgs e)
{
TestLabel.Scale = e.NewValue;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue8988.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12084.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12512.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8981.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3311.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12473.xaml.cs">
<DependentUpon>Issue12473.xaml</DependentUpon>
Expand Down Expand Up @@ -2100,8 +2101,11 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12084.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8981.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12473.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12809.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
Expand Down
14 changes: 13 additions & 1 deletion Xamarin.Forms.Platform.iOS/VisualElementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,22 @@ void update()
transform = transform.Rotate(rotationY * (float)Math.PI / 180.0f, 0.0f, 1.0f, 0.0f);

transform = transform.Rotate(rotation * (float)Math.PI / 180.0f, 0.0f, 0.0f, 1.0f);
#if !__MOBILE__
if (Math.Abs(scaleX - 1) > epsilon || Math.Abs(scaleY - 1) > epsilon)
{
if (scaleX == 0)
scaleX = (float)epsilon;
if (scaleY == 0)
scaleY = (float)epsilon;
if (scale == 0)
scale = (float)epsilon;

transform = transform.Scale(scaleX, scaleY, scale);
}
#else
if (Math.Abs(scaleX - 1) > epsilon || Math.Abs(scaleY - 1) > epsilon)
transform = transform.Scale(scaleX, scaleY, scale);

#endif
if (Foundation.NSThread.IsMain)
{
caLayer.Transform = transform;
Expand Down