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

[Android] Fix crash animate two times the Frame scale #14606

Merged
merged 4 commits into from
Nov 16, 2021
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,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
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"
Title="Test 13236" xmlns:local="using:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Issues.Issue13236">
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="Tap the button. Without exceptions, the test has passed."/>
<Frame
x:Name="TheFrame" BackgroundColor="#2196F3"
Padding="24" CornerRadius="0">
<Label
Text="Issue 13236" HorizontalTextAlignment="Center"
TextColor="White" FontSize="36"/>
</Frame>
<Button
Text="Animate"
Clicked="OnButtonClicked"/>
</StackLayout>
</local:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 13236,
"[Bug] ScaleTo IllegalArgumentException (Android only)",
PlatformAffected.Android)]
public partial class Issue13236 : TestContentPage
{
public Issue13236()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{
}

#if APP
async void OnButtonClicked(System.Object sender, System.EventArgs e)
{
await TheFrame.ScaleTo(0.2, 0);
await TheFrame.ScaleTo(0.2, 0);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11795.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14528.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14286.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13236.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14613.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13930.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11211.xaml.cs" />
Expand Down Expand Up @@ -2278,6 +2279,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14286.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13236.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14613.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
9 changes: 7 additions & 2 deletions Xamarin.Forms.Platform.Android/VisualElementTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@ void UpdateScale()
VisualElement view = _renderer.Element;
AView aview = _renderer.View;

aview.ScaleX = (float)view.Scale * (float)view.ScaleX;
aview.ScaleY = (float)view.Scale * (float)view.ScaleY;
var scale = view.Scale;

if (double.IsNaN(scale))
return;

aview.ScaleX = (float)scale * (float)view.ScaleX;
aview.ScaleY = (float)scale * (float)view.ScaleY;
}

void UpdateTranslationX()
Expand Down